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

    Function last

    • Navigate from a node to its last child or throw an exception if the focused node is a Leaf. Unsafe version of tryLast.

      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'

      // ┬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.last(start)
      expect(Zipper.getValue(hop1)).toBe(5)

      const hop2 = Zipper.last(hop1)
      expect(Zipper.getValue(hop2)).toBe(7)

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