Created
December 5, 2014 18:17
-
-
Save ckpearson/a6f7411fa05fd8a81034 to your computer and use it in GitHub Desktop.
F# Seq.Unfold style method in C#
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static IEnumerable<TRes> Unfold<TRes, T>(this T item, Func<T, Tuple<TRes, T>> generator) | |
{ | |
var res = generator(item); | |
if (res == null) yield break; | |
yield return res.Item1; | |
foreach(var sub in Unfold<TRes, T>(res.Item2, generator)) yield return sub; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment