Skip to content
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

impl<A, B> IntoIterator for (A, B) as Zip #78204

Closed
wants to merge 4 commits into from

Commits on Oct 21, 2020

  1. impl<A, B> IntoIterator for (A, B) as Zip

    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.
    cuviper committed Oct 21, 2020
    Configuration menu
    Copy the full SHA
    4decb2c View commit details
    Browse the repository at this point in the history
  2. Use tuple zips in library/

    cuviper committed Oct 21, 2020
    Configuration menu
    Copy the full SHA
    46d504f View commit details
    Browse the repository at this point in the history
  3. Use tuple zips in compiler/

    cuviper committed Oct 21, 2020
    Configuration menu
    Copy the full SHA
    c834283 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    df72b46 View commit details
    Browse the repository at this point in the history