Method TraverseDepthFirst
View SourceTraverseDepthFirst<T>(T, Func<T, IAsyncEnumerable<T>>)
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.
Declaration
public static IAsyncEnumerable<T> TraverseDepthFirst<T>(T root, Func<T, IAsyncEnumerable<T>> childrenSelector)
Parameters
Type | Name | Description |
---|---|---|
T | root | The root of the tree to traverse. |
Func<T, IAsyncEnumerable<T>> | childrenSelector | The function that produces the children of each element. |
Returns
Type | Description |
---|---|
IAsyncEnumerable<T> | A sequence containing the traversed values. |
Type Parameters
Name | Description |
---|---|
T | The tree node type. |
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.
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|