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

    Function match

    • Match a Tree to leaves and branches.

      Type Parameters

      • A

        Underlying tree type.

      • R

      Parameters

      • matcher: Matcher<A, R>

        A record with the keys onLeaf and onBranch.

      Returns (self: Tree<A>) => R

      Result of the match.

      import * as Tree from 'effect-tree'

      const leaf = Tree.of(1)
      const branch = Tree.from(2, leaf)

      const matcher= Tree.match<number, number>({
      onLeaf: value => value + 1,
      onBranch: (value, forest) => value + forest.length,
      })

      expect(matcher(leaf)).toBe(2)
      expect(matcher(branch)).toBe(3)