-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Add clarity to docs and doctests #14511
Conversation
lib/elixir/lib/enum.ex
Outdated
# [{{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) |
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'm not sure if we need to change it to doctests, since it's example of antipattern, but here we have expression and concreete result, so may be it should be doctested too.
- This important note about zipping maps is only in docs for
zip_with
. May be we should move it to much more widely usedzip/2
, or even copy it tozip/1
andzip/2
?
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.
Order is not guaranteed for maps, as per comment above, so there is no guarantee the result below is what you would get, which is why it is not a doctest. The doctest will fail from time to time.
lib/elixir/lib/enum.ex
Outdated
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. |
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.
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 collected
better? Or will 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." ?
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 returns
may lead to misunderstanding fn
returns the 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.
So perhaps we can say "This function" or "Enum.zip/2
returns"
Co-authored-by: José Valim <[email protected]>
Co-authored-by: José Valim <[email protected]>
Co-authored-by: José Valim <[email protected]>
Co-authored-by: José Valim <[email protected]>
💚 💙 💜 💛 ❤️ |
No description provided.