Add depth-first walk for data tree
This commit is contained in:
parent
b2593d308e
commit
0e72b4b63c
@ -96,10 +96,10 @@ public fun <T> DataTree<T>.asSequence(
|
|||||||
/**
|
/**
|
||||||
* Walk the data tree depth-first
|
* Walk the data tree depth-first
|
||||||
*/
|
*/
|
||||||
public fun <T, TR: GenericDataTree<T,TR>> TR.walk(
|
private fun <T, TR: GenericDataTree<T,TR>> TR.walk(
|
||||||
namePrefix: Name = Name.EMPTY,
|
namePrefix: Name = Name.EMPTY,
|
||||||
): Sequence<TR> = sequence {
|
): Sequence<Pair<Name,TR>> = sequence {
|
||||||
yield(this@walk)
|
yield(namePrefix to this@walk)
|
||||||
items.forEach { (token, tree) ->
|
items.forEach { (token, tree) ->
|
||||||
yieldAll(tree.walk(namePrefix + token))
|
yieldAll(tree.walk(namePrefix + token))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user