/** * Take a `Tree` and a function from `f: (a:A) => Tree` and * return a Tree * * @tsplus static Tree.Aspects flatMap * @tsplus pipeable Tree flatMap */ export function flatMap(f: (a: A) => Tree) { return (self: Tree): Tree => { const { forest, value } = f(self.value) return Tree(value, forest + self.forest.map((a) => a.flatMap(f))) } }