Module tree.imperative.api

This file implements helper functions on trees. It uses a tree-like representation with dictionaries, and the children are stored using arrays. Each node possesses a val attribute labeling the node, and a children attribute containing the array of its children. In a Typescript-like description :

type Node<A,B> = { val: A, children: B }
type TreeI<A> = Node<A, A[]>

This description does not allow for empty trees. A leaf | leaf is considered to be a node with an empty array for its children.

Two ways to create a tree :

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

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

const aTree2 = T.node(6, [ T.leaf(5), T.leaf(4) ]);
anyToString(aTree2); // -> node(6, [leaf(5), leaf(4)])

Index

Functions