flattenTree

fun flattenTree(depth: Int = 0): Sequence<Pair<T, Int>>

Flattens the tree into a sequence of pairs containing each node's value and its depth.

Return

A sequence of pairs where each pair consists of a node's value and its depth in the tree.

Parameters

depth

The initial depth of the root node, default is 0.