walkTree<T, T1> function

Iterable<T1> walkTree<T, T1>(
  1. TreeNode<T> root,
  2. T1 fn(
    1. T node,
    2. Maybe<T> parent
    ), {
  3. Maybe<T> parent = const None(),
})

Visit every node in a tree, call the fn for each and collect the results in an Iterable.

Implementation

Iterable<T1> walkTree<T, T1>(
  TreeNode<T> root,
  T1 Function(T node, Maybe<T> parent) fn, {
  Maybe<T> parent = const None(),
}) sync* {
  yield fn(root.value, parent);
  for (final edge in root.edges) {
    yield* walkTree<T, T1>(
      edge,
      fn,
      parent: Just<T>(root.value),
    );
  }
}