Skip to content

Enum scan improvements #14486

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/elixir/lib/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ defmodule Application do
invoked if it hasn't been done yet. Then, it checks if the dependencies listed
in the `applications` key of the resource file are already started. Having at
least one dependency not started is an error condition. Functions like
`ensure_all_started/1` takes care of starting an application and all of its
`ensure_all_started/1` take care of starting an application and all of its
dependencies for you.

If the application does not have a callback module configured, starting is
Expand Down
24 changes: 17 additions & 7 deletions lib/elixir/lib/enum.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2864,13 +2864,18 @@ defmodule Enum do
end

@doc """
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.
Passes each element from `enumerable` to the `fun` as the first argument,
stores the `fun` result in a list and passes the result as the second argument
for the next computation.

The `fun` isn't applied for the first element of the `enumerable`,
the element is taken as it is.

## Examples

iex> Enum.scan(["a", "b", "c", "d", "e"], &(&1 <> String.first(&2)))
["a", "ba", "cb", "dc", "ed"]

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

Expand All @@ -2891,12 +2896,17 @@ defmodule Enum do
end

@doc """
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 given `acc` as the starting value.
Passes each element from `enumerable` to the `fun` as the first argument,
stores the `fun` result in a list and passes the result as the second argument
for the next computation.

Passes the given `acc` as the second argument for the `fun` with the first element.

## Examples

iex> Enum.scan(["a", "b", "c", "d", "e"], "_", &(&1 <> String.first(&2)))
["a_", "ba", "cb", "dc", "ed"]

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

Expand Down