emel v0.2.0 DataStructures.Tree View Source
Link to this section Summary
Functions
Recursively applies the node
’s content
to the children
The result of invoking f
on node
’s content
and children
The sequences of nodes connecting the tree
’s root with the leafs
Converts the node
into a nice and visible tree for console printing
Link to this section Functions
Recursively applies the node
’s content
to the children
.
Examples
iex> alias DataStructures.Tree.Node
...>
...> DataStructures.Tree.apply(%Node{
...> content: fn _ -> 5 end
...> })
5
iex> alias DataStructures.Tree.Node
...>
...> DataStructures.Tree.apply(%Node{
...> content: fn [x, y] -> x * y end,
...> children: [
...> %Node{
...> content: fn _ -> 7 end
...> },
...> %Node{
...> content: fn _ -> 2 end
...> }
...> ]
...> })
14
iex> alias DataStructures.Tree.Node
...>
...> DataStructures.Tree.apply(%Node{
...> content: fn [x, y] -> x + y end,
...> children: [
...> %Node{
...> content: fn [x] -> x * x end,
...> children: [
...> %Node{
...> content: fn _ -> 3 end
...> }
...> ]
...> },
...> %Node{
...> content: fn _ -> 2 end
...> }
...> ]
...> })
11
The result of invoking f
on node
’s content
and children
.
Examples
iex> alias DataStructures.Tree.Node
...>
...> DataStructures.Tree.map(%Node{
...> content: -2,
...> children: [
...> %Node{
...> content: 1
...> },
...> %Node{
...> children: [
...> %Node{
...> content: 2,
...> children: [
...> %Node{
...> content: 3
...> }
...> ]
...> }]
...> }]
...> },
...> fn x -> 3 * x end)
%DataStructures.Tree.Node{
content: -6,
children: [
%DataStructures.Tree.Node{
content: 3
},
%DataStructures.Tree.Node{
children: [
%DataStructures.Tree.Node{
content: 6,
children: [
%DataStructures.Tree.Node{
content: 9
}]
}
]
}
]
}
The sequences of nodes connecting the tree
’s root with the leafs.
Examples
iex> alias DataStructures.Tree.Node
...>
...> DataStructures.Tree.paths(%Node{
...> content: "root",
...> children: [
...> %Node{
...> content: :leaf
...> },
...> %Node{
...> children: [
...> %Node{
...> content: "second_level",
...> children: [
...> %Node{
...> content: 0
...> }
...> ]
...> }]
...> }]
...> })
[["root", :leaf],
["root", nil, "second_level", 0]]
Converts the node
into a nice and visible tree for console printing.
Examples
iex> alias DataStructures.Tree.Node
...>
...> DataStructures.Tree.pretty(%Node{
...> content: "root",
...> children: [
...> %Node{
...> content: :leaf
...> },
...> %Node{
...> children: [
...> %Node{
...> content: "second_level",
...> children: [
...> %Node{
...> content: 0
...> }
...> ]
...> }]
...> }]
...> })
[
"root",
[
:leaf,
[
[
"second_level",
[
0
]
]
]
]
]