Modules · Data · Collection · Tree

Collection.Tree

A hierarchical tree: every node carries a payload and an array of child branches, each itself a tree. It is immutable — the With… and branch operations return new nodes — and it is the same shape the UI layer uses for nested content.

Contents

Types

Functions

Types

Collection.Tree

A node in a tree: a payload plus an array of child branches, each itself a Collection.Tree. It is the shape the UI layer uses for nested content, and it works for any payload type.

Generics

NameDescription
PayloadTypeThe type of value carried at every node.

Fields

FieldTypeDescription
payloadPayloadTypeThe value stored at this node.
branchesCollection.Array(Collection.Tree(PayloadType))This node's child branches.

Definition

TYPE Collection.Tree(PayloadType)
  FIELD PayloadType payload
  FIELD Collection.Array(Collection.Tree(PayloadType)) branches
A node holds a payload and its child branches; the type is recursive.

Example

LET Collection.Tree(Text) root = Collection.Tree "root" children
LET Text label = root.payload
Constructs a node with a payload and branches, then reads its payload field with dotted access.

Functions

Collection.Tree.AppendBranch

A copy of the node with one branch added to the end.

Generics

NameDescription
PayloadTypeThe node's payload type.

Parameters

NameTypeDescription
treeCollection.Tree(PayloadType)The starting node.
branchCollection.Tree(PayloadType)The child node to add.

Returns

Returns Collection.Tree(PayloadType) — a new node with the extra branch.

Example

LET Collection.Tree(Text) grown = Collection.Tree.AppendBranch root leaf
Adds a child to the end of the branch list, returning a new node.

Collection.Tree.BranchAtOptional

The branch at an index, absent when the index is out of range.

Generics

NameDescription
PayloadTypeThe node's payload type.

Parameters

NameTypeDescription
treeCollection.Tree(PayloadType)The node to read.
indexMaths.IntegerThe branch position to read.

Returns

Returns Collection.Optional(Collection.Tree(PayloadType)) — present with the child branch, or absent when out of range.

Example

LET Collection.Optional(Collection.Tree(Text)) firstChild = Collection.Tree.BranchAtOptional root 0
Absent when the node has no branch at that index.

Collection.Tree.BranchCount

The number of direct branches on the node.

Generics

NameDescription
PayloadTypeThe node's payload type.

Parameters

NameTypeDescription
treeCollection.Tree(PayloadType)The node to measure.

Returns

Returns Maths.Integer — the count of direct child branches.

Example

LET Maths.Integer children = Collection.Tree.BranchCount root
Counts only direct children, not the whole subtree.

Collection.Tree.EachBranch

Runs a block once for each direct branch.

Generics

NameDescription
PayloadTypeThe node's payload type.

Parameters

NameTypeDescription
treeCollection.Tree(PayloadType)The node whose branches to iterate.

Holes

NameReturnsDescription
branchCallbacknothingRun once per direct branch, each in its own reactive branch scope.
Inputs
NameTypeDescription
branchCollection.Tree(PayloadType)The current child node.

Example

Collection.Tree.EachBranch root
  INPUT Collection.Tree(Text) branch
  Ui.Content.Text branch.payload
Walks the direct children; recurse by calling EachBranch again inside the block.

Collection.Tree.HasBranches

Yields yes when the node has at least one branch.

Generics

NameDescription
PayloadTypeThe node's payload type.

Parameters

NameTypeDescription
treeCollection.Tree(PayloadType)The node to test.

Returns

Returns Logic.Maybe — yes when the node has one or more branches — the negation of IsLeaf.

Example

LET Logic.Maybe hasKids = Collection.Tree.HasBranches root
The opposite of IsLeaf.

Collection.Tree.IsLeaf

Yields yes when the node has no branches.

Generics

NameDescription
PayloadTypeThe node's payload type.

Parameters

NameTypeDescription
treeCollection.Tree(PayloadType)The node to test.

Returns

Returns Logic.Maybe — yes when the node has no branches, otherwise no.

Example

LET Logic.Maybe leaf = Collection.Tree.IsLeaf root
A leaf is a node with an empty branch list.

Collection.Tree.RemoveBranch

A copy of the node with the branch at an index removed.

Generics

NameDescription
PayloadTypeThe node's payload type.

Parameters

NameTypeDescription
treeCollection.Tree(PayloadType)The starting node.
indexMaths.IntegerThe branch position to remove.

Returns

Returns Collection.Tree(PayloadType) — a new node with that branch dropped.

Example

LET Collection.Tree(Text) pruned = Collection.Tree.RemoveBranch root 0
Drops the first branch and returns the trimmed node.

Collection.Tree.WithBranches

A copy of the node with a different set of branches, payload unchanged.

Generics

NameDescription
PayloadTypeThe node's payload type.

Parameters

NameTypeDescription
treeCollection.Tree(PayloadType)The starting node.
branchesCollection.Array(Collection.Tree(PayloadType))The branches for the new node.

Returns

Returns Collection.Tree(PayloadType) — a new node with the given branches and the same payload.

Example

LET Collection.Tree(Text) regrown = Collection.Tree.WithBranches root kids
Replaces the whole branch list, keeping the payload.

Collection.Tree.WithPayload

A copy of the node with a different payload, branches unchanged.

Generics

NameDescription
PayloadTypeThe node's payload type.

Parameters

NameTypeDescription
treeCollection.Tree(PayloadType)The starting node.
payloadPayloadTypeThe payload for the new node.

Returns

Returns Collection.Tree(PayloadType) — a new node with the given payload and the same branches.

Example

LET Collection.Tree(Text) renamed = Collection.Tree.WithPayload root "top"
Trees are immutable, so this returns a fresh node with the payload replaced.