-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Add Iterator::zip_longest
.
#19283
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 Iterator::zip_longest
.
#19283
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @aturon (or someone else) soon. |
I like the idea of |
I’m slightly reluctant since |
I don't have a preference on the name, but I think the functionality of |
It’s not so much about the name, it’s an a very similar type used to exist in std and was removed. @aturon, what do you think? |
I don't see what |
I'm personally fine with accepting this on an |
Like `Iterator::zip`, but the returned iterator is as long as the longest of the input iterators rather than shortest, and yields `(Option<A>, Option<B>)` (which can not both be `None`) rather than `(A, B)`. An alternative could be to yield a new `EitherOrBoth` (?) enum that is either `Both(A, B)`, `Left(A)`, or `Right(B)`. Precedent: https://docs.python.org/library/itertools.html#itertools.izip_longest
e6c7aca
to
02cc2f4
Compare
Rebased and switched to I’ve also published this on crates.io: https://crates.io/crates/zip-longest |
@SimonSapin The itertools crate might actually be a good place for this to go for the moment. I can easily imaging us importing adapters from that crate over time, as they prove their worth. |
@aturon: Ok. Feel free to postpone this PR to after 1.0. Whoever maintains the itertools crate: feel free to copy or re-export the zip_longest crate. |
Paging @bluss! I'm going to close this for now. Thanks for your understanding, @SimonSapin. |
ZipLongest originally written by SimonSapin, and dedicated to itertools rust-lang/rust#19283
Done. :-) http://bluss.github.io/rust-itertools/doc/itertools/trait.Itertools.html#method.zip_longest itertools is using the same license as Rust itself, for the very reason that it should be easy to lift things back and forth. |
Like
Iterator::zip
, but the returned iterator is as long as the longest of the input iterators rather than shortest, and yields(Option<A>, Option<B>)
(which can not both beNone
) rather than(A, B)
.An alternative could be to yield a new
EitherOrBoth
(?) enum that is eitherBoth(A, B)
,Left(A)
, orRight(B)
.Precedent: https://docs.python.org/library/itertools.html#itertools.izip_longest