traverse v0.1.0 Traverse
Traverse is a toolset to walk arbitrary Elixir Datastructures.
walk
visits all substructures down to atomic elements.
iex> ds = [:a, {:b, 1, 2}, [:c, 3, 4, 5]]
...> collector = fn ele, acc when is_atom(ele) or is_number(ele) -> [ele|acc]
...> _, acc -> acc end
...> Traverse.walk(ds, [], collector)
[5, 4, 3, :c, 2, 1, :b, :a]
One can return the accumulator boxed in a %Cut{}
struct to avoid traversal of the
subtree.
iex> ds = [add: [1, 2], ignore: [3, 4]]
...> collector = fn {:ignore, _}, acc -> %Traverse.Cut{acc: acc}
...> n, acc when is_number(n) -> [n|acc]
...> _, acc -> acc end
...> Traverse.walk(ds, [], collector)
[2, 1]
Summary
Types
t_simple_walker_fn :: (any, any -> any)
t_traceable_fn ::
(any -> any) |
(any, any -> any) |
(any, any, any -> any)