ImmutableTreeNode
A node in an immutable, persistent n-ary tree. Each node holds a value and an ordered PersistentList of children; nodes never carry a parent back-reference, so a subtree is a self-contained, acyclic value.
Every mutating operation (addChild, removeChild, mapValues) returns a new root and leaves the receiver untouched. Subtrees that are not on the path of the change are reused as the same instances (structural sharing), so updates are cheap and old roots stay valid.
Equality is value-based: two nodes are equal when their values and children are equal (a data class), independent of identity.
Parameters
the value stored in this node.
the ordered, persistent list of child subtrees.
Properties
Functions
Returns this subtree's nodes in level-order (breadth-first: the receiver, then its children, then their children, and so on). Implemented iteratively, so it is safe on arbitrarily deep trees.
Returns this subtree's nodes in post-order (each child subtree in order, then the receiver last). Implemented iteratively, so it is safe on arbitrarily deep trees.
Returns this subtree's nodes in pre-order (the receiver first, then each child subtree in order). Implemented iteratively, so it is safe on arbitrarily deep trees.