Witchcraft v1.0.0-beta Witchcraft.Foldable.Proto protocol View Source
Protocol for the Elixir.Witchcraft.Foldable
type class
For this type class’s API, please refer to Elixir.Witchcraft.Foldable
Link to this section Summary
Functions
Right-associative fold over a structure to alter the structure and/or reduce it to a single summary value. The right-association makes it possible to cease computation on infinite streams of data
Link to this section Types
Link to this section Functions
Link to this function
right_fold(foldable, seed, folder)
View Source
right_fold(Witchcraft.Foldable.t, any, (any, any -> any)) :: any
Right-associative fold over a structure to alter the structure and/or reduce it to a single summary value. The right-association makes it possible to cease computation on infinite streams of data.
The folder must be a binary function, with the second argument being the accumulated value thus far.
Examples
iex> sum = fn xs -> right_fold(xs, 0, &+/2) end
...> sum.([1, 2, 3])
6
...> sum.([4, 5, 6])
15