dynamicTraversal

fun <T> Sequence<T>.dynamicTraversal(revisit: Boolean = false, dropRoots: Boolean = true, traversalAlgorithm: TraversalAlgorithmOption = TraversalAlgorithmOption.BreadthFirst, loadElements: (element: T) -> Sequence<T>): Sequence<T>(source)

Returns a single sequence containing all elements loadElements recursively provides for the elements of the original sequence as well as the elements itself if dropRoots = false is specified. The operation is intermediate and stateless.

For instance, in case of a tree structure, loadElements loads the children, in case of a graph the connected nodes. The order in which the elements are returned depends on the chosen traversalAlgorithm as well as dropRoots. (consult the documentation of the options to get more information).

Since

1.1.0

Parameters

T

the type of the elements in the sequence.

revisit

If set to true (default false), we no longer track visited elements and will re-loadElements in case of a revisit, potentially turning this into an infinite loop. Use this option only if you know that there aren't any cycles or in case the loadElements function is not referentially transparent, i.e. outcome might depend on other factors not only on input.

dropRoots

if set to false (default true) the resulting sequence also includes the elements of the original sequence.

traversalAlgorithm

the algorithm which should be used for traversal (default TraversalAlgorithmOption.BreadthFirst).

loadElements

the function returning the children of a given element in case of a tree / the connected nodes in case of a graph.


@JvmName(name = "dynamicTraversalIterable")
fun <T> Sequence<T>.dynamicTraversal(revisit: Boolean = false, dropRoots: Boolean = true, traversalAlgorithm: TraversalAlgorithmOption = TraversalAlgorithmOption.BreadthFirst, loadElements: (element: T) -> Iterable<T>): Sequence<T>(source)

Returns a single sequence containing all elements loadElements recursively provides for the elements of the original sequence as well as the elements as such if dropRoots = false is specified. The operation is intermediate and stateless.

For instance, in case of a tree structure, loadElements loads the children, in case of a graph the connected nodes. The order in which the elements are returned depends on the chosen traversalAlgorithm as well as dropRoots. (consult the documentation of the options to get more information).

Since

1.1.0

Parameters

T

the type of the elements in the sequence.

revisit

If set to true (default false), we no longer track visited elements and will re-loadElements in case of a revisit, potentially turning this into an infinite loop. Use this option only if you know that there aren't any cycles or in case the loadElements function is not referentially transparent, i.e. outcome might depend on other factors not only on input.

dropRoots

if set to false (default true) the resulting sequence also includes the elements of the original sequence.

traversalAlgorithm

the algorithm which should be used for traversal (default TraversalAlgorithmOption.BreadthFirst).

loadElements

the function returning the children of a given element in case of a tree / the connected nodes in case of a graph.