Iterate over two collections at the same time with the zip
method:
iter1.zip.map
for in iter1.zip
To iterate more you can nest zip()
:
for in iter1.zip.zip
See also Itertools::multizip
.
⚠️ zip()
ends as soon as any of the iterators ends. If the iterators have different lengths, only the shortest one will be fully iterated, and the remaining elements of the longer iterator will be silently ignored. Itertools::zip_eq
catches this.
Example: Rust Playground.