walk<T> static method

void walk<T>(
  1. List<NavSection<T>> sections,
  2. void visit(
    1. NavNode<T> node,
    2. List<NavNode<T>> ancestors
    )
)

Depth-first walk over every node in sections, with its ancestor path.

Implementation

static void walk<T>(
  List<NavSection<T>> sections,
  void Function(NavNode<T> node, List<NavNode<T>> ancestors) visit,
) {
  void rec(List<NavNode<T>> nodes, List<NavNode<T>> path) {
    for (final n in nodes) {
      visit(n, path);
      if (n.hasChildren) rec(n.children, [...path, n]);
    }
  }

  for (final s in sections) {
    rec(s.items, const []);
  }
}