View Source Runbox.Utils.Traversal (runbox v13.0.3)

Summary

Functions

Performs a depth-first pre-order traversal on the given value.

Functions

Performs a depth-first pre-order traversal on the given value.

Transforms each subterm via the given fun, before descending into its descendants.

Example

iex> Traversal.prewalk(
...>    [1, 2, :pi, 4, %{5 => [6, 7]}],
...>    fn
...>      x when is_integer(x) -> Integer.to_string(x)
...>      x when is_list(x) -> Enum.reverse(x)
...>      x -> x
...>    end
...> )
[%{"5" => ["7", "6"]}, "4", :pi, "2", "1"]