traverse<R> method

Iterable<R> traverse<R>(
  1. Map1<RTreeNode<T>, Iterable<R>> callback, {
  2. Predicate1<RTreeNode<T>>? condition,
})

Traverses the tree starting from a given node in depth-first order, calling the given function on each node. A condition function may optionally be passed to filter which nodes get traversed. If condition returns False, then neither the node nor any of its descendants will be traversed.

Implementation

Iterable<R> traverse<R>(Map1<RTreeNode<T>, Iterable<R>> callback,
    {Predicate1<RTreeNode<T>>? condition}) sync* {
  if (condition == null || condition(this)) {
    yield* callback(this);
    if (!isLeaf) {
      for (final entry in entries) {
        yield* entry.child!.traverse(callback, condition: condition);
      }
    }
  }
}