traverse v0.1.0 Traverse.Walker

Implements all the different traversal functions exposed by Traverse.

Summary

Functions

walk implements a top down recursive pre traversal in an arbitrary Elixir datastructure

Types

t_simple_walker_fn :: (any, any -> any)
t_traceable_fn ::
  (any -> any) |
  (any, any -> any) |
  (any, any, any -> any)

Functions

walk(coll, acc, collector)

Specs

walk(any, any, t_simple_walker_fn) :: any

walk implements a top down recursive pre traversal in an arbitrary Elixir datastructure.

Lists and Tuples are traversed, while maps are considered scalar data.

iex>  Traverse.Walker.walk( {1, [2, %{a: 3}, 4], 5}, 0,
  ...>                        fn (n, acc) when is_number(n) -> acc + n
  ...>                            _, acc                    -> acc end )
  12

The traversal function can avoid recursive descent by returning its accumulator value boxed in a %Cut{acc: acc} struct.