AlgorithmmapTreemapTree CallablemapTree<T, U>(x: Tree<T>, f: (x: T) => U): Tree<U>Map a function over the tree starting with the root node, and mapping the children recursively. This function is fully lazy, meaning that we do not evaluate children until they are iterated on. Iteration of the children modify the iterators. Exampleconst t = mapTree(tree(1, [tree(2), tree(3)]), (x) => x + 1)showTree(t)// => └─ 2// ├─ 3// └─ 4showTree(t)// => └─ 2Type parametersTUParametersx: Tree<T>The node root.f: (x: T) => UReturns Tree<U>A mapped tree.
Map a function over the tree starting with the root node, and mapping the children recursively.
This function is fully lazy, meaning that we do not evaluate children until they are iterated on. Iteration of the children modify the iterators.
Example