Elixir Function of the Day

A start page for alchemists! Roll the dice.

Enum.scan/2

 Share!

Function signature:

scan(enumerable, fun)

Documentation:

Applies the given function to each element in the enumerable, storing the result in a list and passing it as the accumulator for the next computation. Uses the first element in the enumerable as the starting value.

Examples

iex> Enum.scan(1..5, &(&1 + &2))
[1, 3, 6, 10, 15]