MoreEnumerableTraverseDepthFirstT Method |
Traverses a tree in a depth-first fashion, starting at a root node and using a user-defined
function to get the children at each node of the tree.
Namespace:
MoreLinq
Assembly:
MoreLinq (in MoreLinq.dll) Version: 2.3.0
Syntax public static IEnumerable<T> TraverseDepthFirst<T>(
T root,
Func<T, IEnumerable<T>> childrenSelector
)
Public Shared Function TraverseDepthFirst(Of T) (
root As T,
childrenSelector As Func(Of T, IEnumerable(Of T))
) As IEnumerable(Of T)
public:
generic<typename T>
static IEnumerable<T>^ TraverseDepthFirst(
T root,
Func<T, IEnumerable<T>^>^ childrenSelector
)
static member TraverseDepthFirst :
root : 'T *
childrenSelector : Func<'T, IEnumerable<'T>> -> IEnumerable<'T>
Parameters
- root
- Type: T
The root of the tree to traverse - childrenSelector
- Type: SystemFuncT, IEnumerableT
The function that produces the children of each element
Type Parameters
- T
- The tree node type
Return Value
Type:
IEnumerableTA sequence containing the traversed values
Remarks
This function defers traversal until needed and streams the results.
The tree is not checked for loops. If the resulting sequence needs to be finite then it is the
responsibility of childrenSelector to ensure that loops are not produced.
See Also