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

Add function core::iter::zip #82917

Merged
merged 5 commits into from
Mar 27, 2021
Merged

Add function core::iter::zip #82917

merged 5 commits into from
Mar 27, 2021

Commits on Mar 26, 2021

  1. Add function core::iter::zip

    This makes it a little easier to `zip` iterators:
    
    ```rust
    for (x, y) in zip(xs, ys) {}
    // vs.
    for (x, y) in xs.into_iter().zip(ys) {}
    ```
    
    You can `zip(&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 zip(zip(xs, ys), zs) {}
    for (x, (y, z)) in zip(xs, zip(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)) {}
    ```
    
    It may also format more nicely, especially when the first iterator is a
    longer chain of methods -- for example:
    
    ```rust
        iter::zip(
            trait_ref.substs.types().skip(1),
            impl_trait_ref.substs.types().skip(1),
        )
        // vs.
        trait_ref
            .substs
            .types()
            .skip(1)
            .zip(impl_trait_ref.substs.types().skip(1))
    ```
    
    This replaces the tuple-pair `IntoIterator` in rust-lang#78204.
    There is prior art for the utility of this in [`itertools::zip`].
    
    [`itertools::zip`]: https://docs.rs/itertools/0.10.0/itertools/fn.zip.html
    cuviper committed Mar 26, 2021
    Configuration menu
    Copy the full SHA
    b362958 View commit details
    Browse the repository at this point in the history
  2. Use iter::zip in library/

    cuviper committed Mar 26, 2021
    Configuration menu
    Copy the full SHA
    3b1f5e3 View commit details
    Browse the repository at this point in the history
  3. Use iter::zip in compiler/

    cuviper committed Mar 26, 2021
    Configuration menu
    Copy the full SHA
    72ebebe View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    e82e812 View commit details
    Browse the repository at this point in the history

Commits on Mar 27, 2021

  1. Configuration menu
    Copy the full SHA
    f0a6052 View commit details
    Browse the repository at this point in the history