/ Published in: C#
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/// <summary> /// Flattens any tree into an enumeration /// </summary> /// <typeparam name="T"></typeparam> /// <param name="item"></param> /// <param name="next"></param> /// <returns></returns> public static IEnumerable<T> Flatten<T>(T item, Func<T, IEnumerable<T>> next) { yield return item; foreach (T child in next(item)) foreach (T flattenedChild in Flatten(child, next)) yield return flattenedChild; }