Skip to content

Commit 945c057

Browse files
Enum scan improvements (#14486)
1 parent 30d1968 commit 945c057

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

lib/elixir/lib/application.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ defmodule Application do
247247
invoked if it hasn't been done yet. Then, it checks if the dependencies listed
248248
in the `applications` key of the resource file are already started. Having at
249249
least one dependency not started is an error condition. Functions like
250-
`ensure_all_started/1` takes care of starting an application and all of its
250+
`ensure_all_started/1` take care of starting an application and all of its
251251
dependencies for you.
252252
253253
If the application does not have a callback module configured, starting is

lib/elixir/lib/enum.ex

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2834,14 +2834,19 @@ defmodule Enum do
28342834
end
28352835

28362836
@doc """
2837-
Applies the given function to each element in the `enumerable`,
2838-
storing the result in a list and passing it as the accumulator
2839-
for the next computation. Uses the first element in the `enumerable`
2840-
as the starting value.
2837+
Passes each element from `enumerable` to the `fun` as the first argument,
2838+
stores the `fun` result in a list and passes the result as the second argument
2839+
for the next computation.
2840+
2841+
The `fun` isn't applied for the first element of the `enumerable`,
2842+
the element is taken as it is.
28412843
28422844
## Examples
28432845
2844-
iex> Enum.scan(1..5, &(&1 + &2))
2846+
iex> Enum.scan(["a", "b", "c", "d", "e"], fn element, acc -> element <> String.first(acc) end)
2847+
["a", "ba", "cb", "dc", "ed"]
2848+
2849+
iex> Enum.scan(1..5, fn element, acc -> element + acc end)
28452850
[1, 3, 6, 10, 15]
28462851
28472852
"""
@@ -2861,13 +2866,18 @@ defmodule Enum do
28612866
end
28622867

28632868
@doc """
2864-
Applies the given function to each element in the `enumerable`,
2865-
storing the result in a list and passing it as the accumulator
2866-
for the next computation. Uses the given `acc` as the starting value.
2869+
Passes each element from `enumerable` to the `fun` as the first argument,
2870+
stores the `fun` result in a list and passes the result as the second argument
2871+
for the next computation.
2872+
2873+
Passes the given `acc` as the second argument for the `fun` with the first element.
28672874
28682875
## Examples
28692876
2870-
iex> Enum.scan(1..5, 0, &(&1 + &2))
2877+
iex> Enum.scan(["a", "b", "c", "d", "e"], "_", fn element, acc -> element <> String.first(acc) end)
2878+
["a_", "ba", "cb", "dc", "ed"]
2879+
2880+
iex> Enum.scan(1..5, 0, fn element, acc -> element + acc end)
28712881
[1, 3, 6, 10, 15]
28722882
28732883
"""

0 commit comments

Comments
 (0)