nustack
ReferenceNutree

walk

Tree walking -- traversal iterators over Term structures.

Module nu.tree.walk.

Tree walking -- traversal iterators over Term structures.

All functions are lazy (generators) and non-mutating. Domain-free: they touch only ._children and identity, so they work on any Term tree.

NameCallMeaning
ancestorstree.ancestors(target, root)Path from root to target (exclusive of target), or None if not found.
bfstree.bfs(root)Breadth-first traversal.
leavestree.leaves(root)Yield only leaf nodes (no children).
postordertree.postorder(root)Depth-first post-order. Yields children before root.
preordertree.preorder(root)Depth-first pre-order. Yields root before children.

ancestors

Path from root to target (exclusive of target), or None if not found.

tree.ancestors(target, root)

Path nu.tree.ancestors. Defined on nu.tree.walk, bound as a function. Builds list[Nu] | None.

Uses identity comparison (is).

Arguments

NameTypeDefaultMeaning
targetNu
rootNu

Undocumented: example.

bfs

Breadth-first traversal.

tree.bfs(root)

Path nu.tree.bfs. Defined on nu.tree.walk, bound as a function. Builds Iterator[Nu].

Arguments

NameTypeDefaultMeaning
rootNu

Undocumented: example.

leaves

Yield only leaf nodes (no children).

tree.leaves(root)

Path nu.tree.leaves. Defined on nu.tree.walk, bound as a function. Builds Iterator[Nu].

Arguments

NameTypeDefaultMeaning
rootNu

Undocumented: example.

postorder

Depth-first post-order. Yields children before root.

tree.postorder(root)

Path nu.tree.postorder. Defined on nu.tree.walk, bound as a function. Builds Iterator[Nu].

Arguments

NameTypeDefaultMeaning
rootNu

Undocumented: example.

preorder

Depth-first pre-order. Yields root before children.

tree.preorder(root)

Path nu.tree.preorder. Defined on nu.tree.walk, bound as a function. Builds Iterator[Nu].

Arguments

NameTypeDefaultMeaning
rootNu

Undocumented: example.

On this page