Created
May 11, 2012 22:33
-
-
Save DexterHaslem/2662834 to your computer and use it in GitHub Desktop.
flatten tree
This file contains 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<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