@@ -2834,14 +2834,19 @@ defmodule Enum do
2834
2834
end
2835
2835
2836
2836
@ 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.
2841
2843
2842
2844
## Examples
2843
2845
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)
2845
2850
[1, 3, 6, 10, 15]
2846
2851
2847
2852
"""
@@ -2861,13 +2866,18 @@ defmodule Enum do
2861
2866
end
2862
2867
2863
2868
@ 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.
2867
2874
2868
2875
## Examples
2869
2876
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)
2871
2881
[1, 3, 6, 10, 15]
2872
2882
2873
2883
"""
0 commit comments