Enum.flat_map_reduce
You're seeing just the function
flat_map_reduce
, go back to Enum module for more information.
Specs
flat_map_reduce(t(), acc(), fun) :: {[any()], acc()} when fun: (element(), acc() -> {t(), acc()} | {:halt, acc()})
Maps and reduces an enumerable
, flattening the given results (only one level deep).
It expects an accumulator and a function that receives each enumerable
element, and must return a tuple containing a new enumerable (often a list)
with the new accumulator or a tuple with :halt
as first element and
the accumulator as second.
Examples
iex> enumerable = 1..100
iex> n = 3
iex> Enum.flat_map_reduce(enumerable, 0, fn x, acc ->
...> if acc < n, do: {[x], acc + 1}, else: {:halt, acc}
...> end)
{[1, 2, 3], 3}
iex> Enum.flat_map_reduce(1..5, 0, fn x, acc -> {[[x]], acc + x} end)
{[[1], [2], [3], [4], [5]], 15}