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 type t_simple_filter_fn()
t_simple_filter_fn() :: (any() -> boolean())
Link to this type t_simple_mapper_fn()
t_simple_mapper_fn() :: (any() -> any())
Link to this type t_simple_walker_fn()
t_simple_walker_fn() :: (any(), any() -> any())
Link to this type t_traceable_fn()
t_traceable_fn() ::
  (any() -> any())
  | (any(), any() -> any())
  | (any(), any(), any() -> any())

Link to this section Functions

Link to this function postwalk!(ele, acc, collector)
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

Link to this function postwalk(coll, acc, collector)
postwalk(any(), any(), t_simple_walker_fn()) :: any()
Link to this function walk!(coll, acc, collector)
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
Link to this function walk(coll, acc, collector)
walk(any(), any(), t_simple_walker_fn()) :: any()

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.