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.

Definition

Namespace: MoreLinq
Assembly: MoreLinq (in MoreLinq.dll) Version: 3.4.0+b99a6a8cc504caf2d48372fe54a2f8116c59cd0c
C#
public static IEnumerable<T> TraverseDepthFirst<T>(
	T root,
	Func<T, IEnumerable<T>> childrenSelector
)

Parameters

root  T
The root of the tree to traverse.
childrenSelector  FuncT, IEnumerableT
The function that produces the children of each element.

Type Parameters

T
The tree node type.

Return Value

IEnumerableT
A sequence containing the traversed values.

Remarks

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.

This function defers traversal until needed and streams the results.

See Also