nephrotoma/node/internal
Types
A node, containing a dictionary of child nodes and a boolean value signifying whether this, too, is an endpoint.
pub type OrderedTreeNode(key) {
OrderedTreeNode(
children: Dict(key, OrderedTreeNode(key)),
exists: Bool,
)
}
Constructors
-
OrderedTreeNode( children: Dict(key, OrderedTreeNode(key)), exists: Bool, )
Functions
pub fn append_list(
node: OrderedTreeNode(a),
list: List(a),
) -> OrderedTreeNode(a)
Add a path as existing in a node.
new(False)
|> append_list([1, 2, 3])
|> exists([1, 2, 3])
// -> True
pub fn exists(node: OrderedTreeNode(a), path: List(a)) -> Bool
Check whether a path exists in a node. Always returns false if either the node or inputted path are empty.
let node = node_from_list([1, 2, 3])
node |> exists([1, 2, 3])
// -> True
node |> exists([1, 2])
// -> False
node |> exists([1, 2, 3, 4])
// -> False
node |> exists([])
// -> False
pub fn with_children(
children: Dict(a, OrderedTreeNode(a)),
) -> OrderedTreeNode(a)
Create a nonexistant node with the specified children.
let node = from_list([1, 2, 3])
with_children(node.children)
|> exists_in_node([1, 2, 3])
// -> True