The underlying type of the tree.
An updated zipper pointing at a new focus.
import {Zipper, from, of} from 'effect-tree'
// ┬1
// ├┬2
// │├─3
// │└─4
// └┬5
// ├─6
// └─7
const tree = from(1, from(2, of(3), of(4)), from(5, of(6), of(7)))
const start = Zipper.fromTree(tree)
const hop1 = Zipper.depthFirst(start)
expect(Zipper.getValue(hop1)).toBe(2)
const hop2 = Zipper.depthFirst(hop1)
expect(Zipper.getValue(hop2)).toBe(3)
const hop3 = Zipper.depthFirst(hop2)
expect(Zipper.getValue(hop3)).toBe(4)
const hop4 = Zipper.depthFirst(hop3)
expect(Zipper.getValue(hop4)).toBe(5)
const hop5 = Zipper.depthFirst(hop4)
expect(Zipper.getValue(hop5)).toBe(6)
const hop6 = Zipper.depthFirst(hop5)
expect(Zipper.getValue(hop6)).toBe(7)
// Out-of-bounds exception when nowhere left to go.
expect(() => Zipper.depthFirst(hop6)).toThrow(/getOrThrow/)
Navigate from a node to the next node in a depth-first pre-order traversal, where parents are visited before their children, and both are visited before the next sibling of the parent. For example:
Returns
Option.nonewhen the final node in the traversal has been reached.This is the unsafe version of tryDepthFirst.