Skip to content

Commit c006c92

Browse files
Improve Enum.scan/2 docs
1 parent 5598b05 commit c006c92

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

lib/elixir/lib/enum.ex

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2864,13 +2864,16 @@ defmodule Enum do
28642864
end
28652865

28662866
@doc """
2867-
Applies the given function to each element in the `enumerable`,
2868-
storing the result in a list and passing it as the accumulator
2869-
for the next computation. Uses the first element in the `enumerable`
2870-
as the starting value.
2867+
Passes each element from `enumerable` to the `fun` as the first argument,
2868+
stores the `fun` result in a list and passes the result as the second argument
2869+
for the next computation. The `fun` isn't applied for the first element
2870+
of the `enumerable`, the element is taken as it is.
28712871
28722872
## Examples
28732873
2874+
iex> Enum.scan(["a", "b", "c", "d", "e"], &(&1 <> String.first(&2)))
2875+
["a", "ba", "cb", "dc", "ed"]
2876+
28742877
iex> Enum.scan(1..5, &(&1 + &2))
28752878
[1, 3, 6, 10, 15]
28762879

0 commit comments

Comments
 (0)