Module tree.lazy.api

This file implements helper functions on lazy trees. It uses a tree-like representation, as the one used for the imperative trees, with the additional property that the children of a node are lazy values.

In a Typescript-like description :

type TreeIL<T> = {
val: T,
children: Lazy<TreeIL<T>[]>,
};

These trees are well adapted to represent arbitrary-deep trees, where the lazy values can unfold the children of a node at will.

Here are two different ways to create lists :

import * as L from "./src/utils/lazy.js";
import * as T from "./src/utils/tree.lazy.api.js";

const aTree1 = T.node(1, L.evaluated([ T.leaf(2), T.leaf(3) ]));
anyToString(aTree1); // -> node(1, [leaf(2),leaf(3)])

const aTree2 = T.node(1, L.freeze(() => [ T.leaf(2), T.leaf(3) ]));
anyToString(aTree2); // -> node(1, [<frozen>])
T.treeThawAtDepth(aTree2, 1);
anyToString(aTree2); // -> node(1, [leaf(2),leaf(3)])

Index

Functions