Module tree.functional.api

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

type Node<A,B> = { val: A, children: B }
type Tree<A> = Node<A, List<A>>

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

Two ways to create a tree :

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

const aTree1 = T.node(1, L.cons(T.node(2, L.nil), L.cons(T.node(3, L.nil), L.nil)));
anyToString(aTree1); // -> node(1, (|leaf(2), leaf(3)|))

const aTree2 = T.node(6, L.cons(T.leaf(5), L.cons(T.leaf(4), L.nil)));
anyToString(aTree2); // -> node(6, (|leaf(5), leaf(4)|))

Index

Functions