-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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 custom nth_back for Zip #60574
Add custom nth_back for Zip #60574
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @scottmcm (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
Since the underlying iterators may have side-effects, I don't think we can return early when |
@timvermeulen, returning early might be ok, especially if you are leveraging the underlaying nth_back. The forward next also does short-circuiting, its documentation sais: "If the first iterator returns None, zip will short-circuit and next will not be called on the second iterator." Maybe we can use a similar behaviour here. |
@koalatux That guarantee is specific to So short-circuiting |
ping from triage @scottmcm waiting for your review on this |
|
||
#[inline] | ||
fn nth_back(&mut self, mut n: usize) -> Option<(A::Item, B::Item)> { | ||
while let Some(x) = ZipImpl::next_back(self) { |
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.
The default implementation of nth_back
calls Iterator::next_back
in a loop, which seems like it'd be just as good as this one? It looks like ZipImpl::nth
exists, so I'd have expected the change here to add ZipImpl::nth_back
and specialize it the same way.
Ping from triage @mdnight, can you address the review comment? |
Ping from triage @mdnight please address the review comment |
@scottmcm Triage: Thanks for the PR but I'm going to close this due to lack of movement. |
Implementation of nth_back for Zip.
Part of #54054
r? @scottmcm