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

    Function up

    • Navigate from a node to its parent or throw an exception if the focused node is a tree root. Unsafe version of tryUp.

      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
      // └┬5
      // ├─6
      // └─7
      const tree = from(1, from(2, of(3), of(4)), from(5, of(6), of(7)))

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

      const hop1 = Zipper.up(start)
      expect(Zipper.getValue(hop1)).toBe(2)

      const hop2 = Zipper.up(hop1)
      expect(Zipper.getValue(hop2)).toBe(1)

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