Macro itertools::izip
[−]
[src]
macro_rules! izip { ( @closure $p:pat => $tup:expr ) => { ... }; ( @closure $p:pat => ( $($tup:tt)* ) , $_iter:expr $( , $tail:expr )* ) => { ... }; ( $first:expr $( , $rest:expr )* $(,)* ) => { ... }; }
Create an iterator running multiple iterators in lockstep.
The izip!
iterator yields elements until any subiterator
returns None
.
This is a version of the standard .zip()
that's supporting more than
two iterators. The iterator elment type is a tuple with one element
from each of the input iterators. Just like .zip()
, the iteration stops
when the shortest of the inputs reaches its end.
Note: The result of this macro is an iterator composed of
repeated .zip()
and a .map()
; it has an anonymous type.
Prefer this macro izip!()
over multizip
for the performance benefits
of using the standard library .zip()
.
#[macro_use] extern crate itertools; // iterate over three sequences side-by-side let mut results = [0, 0, 0, 0]; let inputs = [3, 7, 9, 6]; for (r, index, input) in izip!(&mut results, 0..10, &inputs) { *r = index * 10 + input; } assert_eq!(results, [0 + 3, 10 + 7, 29, 36]);
Note: To enable the macros in this crate, use the #[macro_use]
attribute when importing the crate:
#[macro_use] extern crate itertools;