Skip to content

Instantly share code, notes, and snippets.

@DexterHaslem
Created May 11, 2012 22:33
Show Gist options
  • Save DexterHaslem/2662834 to your computer and use it in GitHub Desktop.
Save DexterHaslem/2662834 to your computer and use it in GitHub Desktop.
flatten tree
public static IEnumerable<T> FlattenTree<T>(IEnumerable<T> list, Func<T, IEnumerable<T>> subitems)
{
foreach (T child in list)
{
yield return child;
foreach (T other in FlattenTree(subitems(child), subitems))
yield return other;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment