effect-tree
    Preparing search index...

    Type Alias TreeArray<A>

    TreeArray: A | [A, TreeArray<A>[]]

    The type of trees encoded as nested arrays. In this encoding a leaf is encoded as a single value:

    const leaf: TreeArray<number> = 1 // A tree with a single node
    

    While a branch node is encoded as a pair of [A, TreeArray<A>[]], with the first element being the root node value and the second element being its child nodes encoded as a TreeArray. So if we add two children to our leaf it would encode as:

    const branch: TreeArray<number> = [1, [2, 3]] // A tree with a 3 nodes
    

    Adding children to a leaf in this encoding converts it into a pair of [values, nodes]. Here is a larger tree encoded as nested arrays:

    // ┬1
    // ├┬2
    // │├─3
    // │└─4
    // ├┬5
    // │└─6
    // └─7
    const tree = make(1, [
    make(2, [of(3), of(4)]),
    make(5, [of(6)]),
    of(7),
    ])

    const encoded = codec.array.encode(tree)
    // [1, [[2, [3, 4]], [5, [6]], 7]]

    Type Parameters

    • A