Skip to content

Instantly share code, notes, and snippets.

@ckpearson
Created December 5, 2014 18:17
Show Gist options
  • Save ckpearson/a6f7411fa05fd8a81034 to your computer and use it in GitHub Desktop.
Save ckpearson/a6f7411fa05fd8a81034 to your computer and use it in GitHub Desktop.
F# Seq.Unfold style method in C#
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