-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Consider tuple iteration #930
Comments
It doesn't really need to be syntax sugar. If it's done as an IntoIterator impl on tuples then it's not exactly syntax, is it? I've written code like:
too many times. This would be much appreciated and make iterating over several iterables at once far easier to read, in my opinion. |
I would love to see this. Zip syntax right now is kind of ugly and unreadable, IMHO. I almost prefer to use indices instead of iterators half the time. I don't think there's any reason why we couldn't have both. |
See #1650 which presents one way to do this. |
I'm not really sure I see how that would make this possible. I'm just looking for an impl of That is, for x in (&[1, 2, 3], &[4, 5, 6]) {
println!("{:?}", x);
} would be equivalent to for x in (&[1,2,3]).into_iter().zip(&[4,5,6]) {
println!("{:?}", x);
} |
Ah sorry, I misunderstood what you were asking for. What I had in mind was somelike like a |
Should rust-lang/rust#43242 be part of this RFC or a separate one? |
This makes it a little easier to `zip` iterators: ```rust for (x, y) in (xs, ys) {} // vs. for (x, y) in xs.into_iter().zip(ys) {} ``` You can iterate `(&mut xs, &ys)` for the conventional `iter_mut()` and `iter()`, respectively. This can also support arbitrary nesting, where it's easier to see the item layout than with arbitrary `zip` chains: ```rust for ((x, y), z) in ((xs, ys), zs) {} for (x, (y, z)) in (xs, (ys, zs)) {} // vs. for ((x, y), z) in xs.into_iter().zip(ys).zip(xz) {} for (x, (y, z)) in xs.into_iter().zip((ys.into_iter().zip(xz)) {} ``` Only tuple pairs are implemented for now. It's possible to implement longer tuples, but that would require a new iterator type to produce those tuple items. See itertools' [`Zip`] and rayon's [`MultiZip`] for prior art there. [`Zip`]: https://docs.rs/itertools/0.9.0/itertools/structs/struct.Zip.html [`MultiZip`]: https://docs.rs/rayon/1.4.1/rayon/iter/struct.MultiZip.html See also rust-lang/rfcs#870 and rust-lang/rfcs#930.
Original proposed in #870, some syntax sugar for iterating over multiple things.
The text was updated successfully, but these errors were encountered: