Skip to content
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

Mention iter::zip in the documentation for Iterator::zip #91960

Closed
scottmcm opened this issue Dec 15, 2021 · 3 comments · Fixed by #92899
Closed

Mention iter::zip in the documentation for Iterator::zip #91960

scottmcm opened this issue Dec 15, 2021 · 3 comments · Fixed by #92899
Assignees
Labels
E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Comments

@scottmcm
Copy link
Member

scottmcm commented Dec 15, 2021

Now that iter::zip is stable (#91881), we can mention it in the documentation of other stable methods.

It would thus be nice to mention it in the documentation for Iterator::zip, both to help people discover it and to help them decide when to use which.

It already has a s1.iter().zip(s2); example talking about IntoIterator, so maybe it would make sense to mention iter::zip in terms of when you want that on both sides, as zip(s1, s2).

If you start working on this, please comment @rustbot claim to help avoid duplicate effort.

@scottmcm scottmcm added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Dec 15, 2021
@cameron1024
Copy link
Contributor

@rustbot claim

@cameron1024
Copy link
Contributor

I've just had a look through the PRs, am I right in thinking the purpose of this is just a nicer syntax for zipping iterators? Should the docs suggest preferring zip(as, bs) over as.into_iter().zip(bs), or are there reasons why you'd prefer one over the other?

@scottmcm
Copy link
Member Author

scottmcm commented Dec 15, 2021

#82917 has the reasoning why iter::zip was added.

I think it depends how similar the sides are. If the call chain in them is similar in structure, and particularly when it's things that are IntoIterator but not Iterator (like arrays or reference-to-vector) then I think the function is better. But if you have a long chain (maybe with a big map closure) that's then zipped with something simple, the method could be easier to read.

TBH, I tended to write Iterator::zip(a.iter(), b.iter()) anyway (because I prefer function-like form for symmetric things) so I'd probably use the function most of the time. But I don't know how pervasive that behaviour is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants