-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Add clarity to docs and doctests #14511
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
Changes from 1 commit
5ac58b6
cc1a4df
3ccd1de
5259f92
cf9e53a
e95c527
5edb6e9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3924,8 +3924,9 @@ defmodule Enum do | |
| If an integer offset is given as `fun_or_offset`, it will index from the given | ||
| offset instead of from zero. | ||
|
|
||
| If a function is given as `fun_or_offset`, it will index by invoking the function | ||
| for each element and index (zero-based) of the enumerable. | ||
| If a 2-arity function is given as `fun_or_offset`, the function will be invoked | ||
| for each element in `enumerable` as the first argument and with a zero-based | ||
| index as the second. The result of the invocation will be listed. | ||
|
|
||
| ## Examples | ||
|
|
||
|
|
@@ -4036,10 +4037,10 @@ defmodule Enum do | |
| key in the left map and the matching key in the right map, but there is no such | ||
| guarantee because map keys are not ordered! Consider the following: | ||
|
|
||
| left = %{:a => 1, 1 => 3} | ||
| right = %{:a => 1, :b => :c} | ||
| Enum.zip(left, right) | ||
| # [{{1, 3}, {:a, 1}}, {{:a, 1}, {:b, :c}}] | ||
| iex> left = %{:a => 1, 1 => 3} | ||
| iex> right = %{:a => 1, :b => :c} | ||
| iex> Enum.zip(left, right) | ||
|
||
| [{{1, 3}, {:a, 1}}, {{:a, 1}, {:b, :c}}] | ||
|
|
||
| As you can see `:a` does not get paired with `:a`. If this is what you want, | ||
| you should use `Map.merge/3`. | ||
|
|
@@ -4109,11 +4110,11 @@ defmodule Enum do | |
|
|
||
| ## Examples | ||
|
|
||
| iex> Enum.zip_reduce([1, 2], [3, 4], 0, fn x, y, acc -> x + y + acc end) | ||
| iex> Enum.zip_reduce([1, 2], [3, 4, 5], 0, fn x, y, acc -> x + y + acc end) | ||
dmitrykleymenov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 10 | ||
|
|
||
| iex> Enum.zip_reduce([1, 2], [3, 4], [], fn x, y, acc -> [x + y | acc] end) | ||
| [6, 4] | ||
| iex> Enum.zip_reduce([1, 2, 3], [4, 5], [], fn x, y, acc -> [x + y | acc] end) | ||
dmitrykleymenov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| [7, 5] | ||
| """ | ||
| @doc since: "1.12.0" | ||
| @spec zip_reduce(t, t, acc, (enum1_elem :: term, enum2_elem :: term, acc -> acc)) :: acc | ||
|
|
@@ -4143,13 +4144,13 @@ defmodule Enum do | |
|
|
||
| ## Examples | ||
|
|
||
| iex> enums = [[1, 1], [2, 2], [3, 3]] | ||
| iex> enums = [[1, 1, 1, 1], [2, 2, 2], [3, 3]] | ||
dmitrykleymenov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ...> Enum.zip_reduce(enums, [], fn elements, acc -> | ||
| ...> [List.to_tuple(elements) | acc] | ||
| ...> end) | ||
| [{1, 2, 3}, {1, 2, 3}] | ||
|
|
||
| iex> enums = [[1, 2], [a: 3, b: 4], [5, 6]] | ||
| iex> enums = [[1, 2], [a: 3, b: 4], [5, 6, 7]] | ||
dmitrykleymenov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ...> Enum.zip_reduce(enums, [], fn elements, acc -> | ||
| ...> [List.to_tuple(elements) | acc] | ||
| ...> end) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"will be listed" is not really clear what it means in this context.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is
will be collectedbetter? Orwill be collected in the result list?The return value of the anonimous function will be collected in the resulting list?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"It returns a list with the result of each invocation." ?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the whole paragraph is about the anonimous function, and
it returnsmay lead to misunderstandingfnreturns the listThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So perhaps we can say "This function" or "
Enum.zip/2returns"