walkTree function

bool walkTree(
  1. FNode root,
  2. bool visitor(
    1. FNode node,
    2. FNode? parent
    ), {
  3. FNode? parent,
})

Visits all nodes in DFS pre-order, calling visitor on each. If visitor returns false, stops the visit.

Implementation

bool walkTree(FNode root, bool Function(FNode node, FNode? parent) visitor,
    {FNode? parent}) {
  if (!visitor(root, parent)) return false;
  for (final child in childrenOf(root)) {
    if (!walkTree(child, visitor, parent: root)) return false;
  }
  return true;
}