Skip to content

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

Merged
merged 7 commits into from
May 21, 2025

Conversation

dmitrykleymenov
Copy link
Contributor

No description provided.

# [{{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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. 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.
  2. This important note about zipping maps is only in docs for zip_with. May be we should move it to much more widely used zip/2, or even copy it to zip/1 and zip/2?

Copy link
Member

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.

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.
Copy link
Member

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.

Copy link
Contributor Author

@dmitrykleymenov dmitrykleymenov May 21, 2025

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?

Copy link
Member

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." ?

Copy link
Contributor Author

@dmitrykleymenov dmitrykleymenov May 21, 2025

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

Copy link
Member

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"

@josevalim josevalim merged commit d636a0a into elixir-lang:main May 21, 2025
23 of 24 checks passed
@josevalim
Copy link
Member

💚 💙 💜 💛 ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants