-
Notifications
You must be signed in to change notification settings - Fork 20
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
Implement IntoIterator for tuples with values which are IntoIterator themselves #513
Comments
The previous attempt in 2020 rust-lang/rust#78204 (comment) was closed because
I don't think the stance is changed here (the free function |
Thanks for the context. In addition, this would allow for |
We discussed this in today's @rust-lang/libs-api meeting. We had a long and vigorous discussion. :) We were very sympathetic to this approach. We also had concerns about possible ambiguity. Note, in particular, that Python has different behavior here:
Our current thinking is that we're inclined to not add these However, we're going to sleep on it and consider again in a future meeting. |
Also, some of us in the meeting were amenable to adding |
let xs = vec![1, 3, 5];
let ys = vec![2, 4, 6];
let zs = vec![3, 7, 11];
for (x, y, z) in (&xs, &ys, &zs) {
assert!(*x + *y == *z);
} For me, at least, this just seems, aesthetically, a really nice language outcome for Rust. It feels very natural in this case, and this case seems like it would be by far the predominant one. My feeling is that there's no other plausible meaning for And so, since we'd never use this space for anything else, I do feel like we should seriously consider using the space for this, given the pleasingness of the outcome. This has to be weighed, of course, against the fact that people would need to learn about this meaning of |
FWIW, I personally agree, but we didn't have consensus for that path. |
I agree that the In Similarly Having an explicit |
Thanks a lot for the consideration and discussion! One question with regard to variadic generics is, what would that look like? |
well, with rust-lang/rfcs#3723, you can just write |
Since we couldn't get a team consensus on this, we're closing this ACP. We may re-open this in the future if variadic generics end up not happening for some reason. |
Proposal
Problem statement
It is awkward to use
Iterator::zip
for tuples of larger arities than 2, as you need to chain calls to zip and iter() in the right places, as well as wrap your head around the correct nesting of the tuples. ImplementingIntoIterator
for tuples would make it very natural to call.Motivating examples or use cases
Here's a small example of two ways to use the
IntoIterator
impl.itertools
has also identified that nested tuples can be confusing, and added a convenience helper method (https://docs.rs/itertools/latest/itertools/fn.cons_tuples.html).In addition, it would play nice with the upcoming stabilizations of
Extend
andFromIterator
for tuples.Solution sketch
The implementations are pretty straight forward. Specialization similar to what is done in
Zip
could be added, as well, but isn't required just to get the API out there.Alternatives
Do nothing and keep using chained
zip
calls and nested tuples.Links and related work
This was already discussed many years ago with the intent to replace
zip
: rust-lang/rfcs#870. An old RFC discussion was begun in rust-lang/rfcs#930.What happens now?
This issue contains an API change proposal (or ACP) and is part of the libs-api team feature lifecycle. Once this issue is filed, the libs-api team will review open proposals as capability becomes available. Current response times do not have a clear estimate, but may be up to several months.
Possible responses
The libs team may respond in various different ways. First, the team will consider the problem (this doesn't require any concrete solution or alternatives to have been proposed):
Second, if there's a concrete solution:
The text was updated successfully, but these errors were encountered: