@@ -3924,8 +3924,9 @@ defmodule Enum do
3924
3924
If an integer offset is given as `fun_or_offset`, it will index from the given
3925
3925
offset instead of from zero.
3926
3926
3927
- If a function is given as `fun_or_offset`, it will index by invoking the function
3928
- for each element and index (zero-based) of the enumerable.
3927
+ If a 2-arity function is given as `fun_or_offset`, the function will be invoked
3928
+ for each element in `enumerable` as the first argument and with a zero-based
3929
+ index as the second. `with_index/2` returns a list with the result of each invocation.
3929
3930
3930
3931
## Examples
3931
3932
@@ -4036,10 +4037,10 @@ defmodule Enum do
4036
4037
key in the left map and the matching key in the right map, but there is no such
4037
4038
guarantee because map keys are not ordered! Consider the following:
4038
4039
4039
- left = %{:a => 1, 1 => 3}
4040
+ left = %{:a => 1, 1 => 3}
4040
4041
right = %{:a => 1, :b => :c}
4041
4042
Enum.zip(left, right)
4042
- # [{{1, 3}, {:a, 1}}, {{:a, 1}, {:b, :c}}]
4043
+ #=> [{{1, 3}, {:a, 1}}, {{:a, 1}, {:b, :c}}]
4043
4044
4044
4045
As you can see `:a` does not get paired with `:a`. If this is what you want,
4045
4046
you should use `Map.merge/3`.
@@ -4112,8 +4113,11 @@ defmodule Enum do
4112
4113
iex> Enum.zip_reduce([1, 2], [3, 4], 0, fn x, y, acc -> x + y + acc end)
4113
4114
10
4114
4115
4115
- iex> Enum.zip_reduce([1, 2], [3, 4], [], fn x, y, acc -> [x + y | acc] end)
4116
- [6, 4]
4116
+ If one of the lists has more entries than the others,
4117
+ those entries are discarded:
4118
+
4119
+ iex> Enum.zip_reduce([1, 2, 3], [4, 5], [], fn x, y, acc -> [x + y | acc] end)
4120
+ [7, 5]
4117
4121
"""
4118
4122
@ doc since: "1.12.0"
4119
4123
@ spec zip_reduce ( t , t , acc , ( enum1_elem :: term , enum2_elem :: term , acc -> acc ) ) :: acc
@@ -4149,7 +4153,10 @@ defmodule Enum do
4149
4153
...> end)
4150
4154
[{1, 2, 3}, {1, 2, 3}]
4151
4155
4152
- iex> enums = [[1, 2], [a: 3, b: 4], [5, 6]]
4156
+ If one of the lists has more entries than the others,
4157
+ those entries are discarded:
4158
+
4159
+ iex> enums = [[1, 2], [a: 3, b: 4], [5, 6, 7]]
4153
4160
...> Enum.zip_reduce(enums, [], fn elements, acc ->
4154
4161
...> [List.to_tuple(elements) | acc]
4155
4162
...> end)
0 commit comments