effect-tree - v1.0.36
    Preparing search index...

    Function next

    • Navigate from a node to its next sibling or throw an exception if the focused node is the last node in its forest. Unsafe version of tryNext.

      Type Parameters

      • A

        The underlying type of the tree.

      Parameters

      Returns Zipper.Zipper<A>

      An updated zipper pointing at a new focus.

      import {Zipper, from, of} from 'effect-tree'
      import {pipe} from 'effect'

      // ┬1
      // ├─2
      // ├─3
      // └─4
      const tree = from(1, of(2), of(3), of(4))

      const start = pipe(tree, Zipper.fromTree, Zipper.head)

      const hop1 = Zipper.next(start)
      expect(Zipper.getValue(hop1)).toBe(3)

      const hop2 = Zipper.next(hop1)
      expect(Zipper.getValue(hop2)).toBe(4)

      // Out-of-bounds exception when nowhere left to go.
      expect(() => Zipper.next(hop2)).toThrow(/getOrThrow/)