graphqexl v0.1.0-alpha-rc.24 Treex.Traverse
Basic tree traversal algorithms, implementing depth-first and breadth-first traversal.
Link to this section Summary
Functions
Traverse the given tree and invoke the given operation function on each node.
The function operation and the algorithm to use (one of :bfs
or :dfs
).
Link to this section Types
Link to this section Functions
Traverse the given tree and invoke the given operation function on each node.
The function operation and the algorithm to use (one of :bfs
or :dfs
).
An operation function must have the type:
(t:Treex.Tree.t/0, t:Treex.Tree.history -> t:Treex.Tree.result/0)
with the form:
fn node, history -> body end
where node
is the current node and history
is the accumulated list of traverse operated nodes.
Returns: [t:Treex.Tree.result/0]
Examples
iex> Treex.TreeTraversal.traverse(nil, fn x, , -> {:continue, x} end, :bfs) []
iex> Treex ..(1)> .Traverse ..(1)> .traverse(%Treex.Tree{value: 1, ..(1)> children: [%Treex.Tree{value: 2}, ..(1)> %Treex.Tree{value: 3}, ..(1)> %Treex.Tree{value: 4}]}, ..(1)> fn x, , -> {:continue, x} end, ..(1)> :bfs) [4, 3, 2, 1]