Skip to content

Consider tuple iteration #930

Description

@brson

Original proposed in #870, some syntax sugar for iterating over multiple things.

Activity

  1. tomjakubowski commented on Mar 13, 2016

    @tomjakubowski
    Contributor

    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:

    for (bx, (by, bz)) in xs.iter().zip(ys.iter().zip(zs.iter_mut())) { }
    

    too many times. This would be much appreciated and make iterating over several iterables at once far easier to read, in my opinion.

  2. devyn commented on Aug 25, 2016

    @devyn

    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.

  3. Amanieu commented on Aug 25, 2016

    @Amanieu
    Member

    See #1650 which presents one way to do this.

  4. added
    T-langRelevant to the language team, which will review and decide on the RFC.
    T-libs-api[DEPRECATED; DO NOT USE]
    on Aug 25, 2016
  5. devyn commented on Aug 26, 2016

    @devyn

    I'm not really sure I see how that would make this possible. I'm just looking for an impl of IntoIterator for the tuples where every element implements IntoIterator that behaves somewhat like zip does.

    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);
    }
  6. Amanieu commented on Aug 26, 2016

    @Amanieu
    Member

    Ah sorry, I misunderstood what you were asking for. What I had in mind was somelike like a map operation that you could perform on each element of a tuple, even if they have different types.

  7. Kixunil commented on Jul 20, 2017

    @Kixunil

    Should rust-lang/rust#43242 be part of this RFC or a separate one?

  8. added
    T-libsRelevant to the library team, which will review and decide on the RFC.
    and removed
    T-libs-api[DEPRECATED; DO NOT USE]
    on Aug 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-langRelevant to the language team, which will review and decide on the RFC.T-libsRelevant to the library team, which will review and decide on the RFC.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions