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

    Function remove

    • Remove the current focused tree node from the tree, and return the zipper focused on the next sibling.

      When no next sibling exists, for example if the node is the last in the forest, focuses up on the parent of the removed node.

      When the zipper is focused on tree root returns Option.none().

      Type Parameters

      • A

        The underlying type of the tree.

      Parameters

      Returns Option<Zipper.Zipper<A>>

      A zipper without the previously focused node focused on next node, or failing that, on the parent node. If the zipper is focused on the tree root returns Option.none().

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

      const tree = from(1, of(2))

      const changed = pipe(
      tree,
      Zipper.fromTree,
      Zipper.head,
      Zipper.remove,
      Option.map(Zipper.toTree),
      )
      expect(changed, 'leaf').toEqual(Option.some(of(1)))

      const removeRoot = pipe(
      changed,
      Option.map(Zipper.fromTree),
      Option.flatMap(Zipper.remove),
      )
      expect(removeRoot, 'root').toEqual(Option.none())