traverse v1.0.1 Traverse.Walker
Implements traversal functions, structure is not maintained unless the traversal functions do so.
Link to this section Summary
Functions
Like walk! implements collector augmentation for partial collector functions
walk! implements a top down recursive pre traversal in an arbitrary Elixir datastructure.
In contrast to walk it augments partial collcetor functions with the second arg of two identity
walk implements a top down recursive pre traversal in an arbitrary Elixir datastructure
Link to this section Types
Link to this section Functions
postwalk!(any(), any(), t_simple_walker_fn()) :: any()
Like walk! implements collector augmentation for partial collector functions
iex(1)> Traverse.Walker.postwalk!( {1, [2, %{a: 3}, 4], 5}, 0, …(1)> fn (n, acc) when is_number(n) -> acc + n end) 15
postwalk(any(), any(), t_simple_walker_fn()) :: any()
walk!(any(), any(), t_simple_walker_fn()) :: any()
walk! implements a top down recursive pre traversal in an arbitrary Elixir datastructure.
In contrast to walk it augments partial collcetor functions with the second arg of two identity
_, acc -> acc
iex(3)> Traverse.Walker.walk!( {1, [2, %{a: 3}, 4], 5}, 0,
...(3)> fn (n, acc) when is_number(n) -> acc + n end)
15
walk implements a top down recursive pre traversal in an arbitrary Elixir datastructure.
iex(2)> Traverse.Walker.walk( {1, [2, %{a: 3}, 4], 5}, 0,
...(2)> fn (n, acc) when is_number(n) -> acc + n
...(2)> _, acc -> acc end )
15
The traversal function can avoid recursive descent by returning its accumulator value boxed in a %Cut{acc: acc} struct.