Skip to content

mapTree

mapTree<T, U>(x, f): 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.

Example

const t = mapTree(tree(1, [tree(2), tree(3)]), (x) => x + 1)
showTree(t)
// => └─ 2
// ├─ 3
// └─ 4
showTree(t)
// => └─ 2

Type Parameters

T

U

Parameters

x

Tree<T>

The node root.

f

(x) => U

Returns

Tree<U>

A mapped tree.