Match a Tree to leaves and branches.
Underlying tree type.
A record with the keys onLeaf and onBranch.
onLeaf
onBranch
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) Copy
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)
Match a Tree to leaves and branches.