tree-zipper
Installation
SKILL.md
When to use
A tree zipper is a cursor for immutable trees. State = (focus, trail).
Rules
- focus is the current subtree
- trail is a list of "breadcrumbs" describing the path from root to focus
- Each crumb remembers the parent's value plus the siblings NOT taken
- down_left/down_right push a crumb and make the chosen child the new focus
- up pops the top crumb, rebuilds the parent, and makes that parent the new focus
- set_value replaces the focused subtree's value
- to_tree walks all the way up to rebuild the whole tree
- Key invariant: you can ALWAYS reconstruct the full original tree from (focus, trail)
- Equality of two zippers = equality of the fully-reconstructed trees, NOT of the raw (focus, trail) pairs
- NEVER compare raw (focus, trail) pairs for equality