itertools::iproduct! [] [src]

macro_rules! iproduct {
    ($I:expr) => (
        (::std::iter::IntoIterator::into_iter($I))
    );
    ($I:expr, $J:expr) => (
        $crate::Product::new(iproduct!($I), iproduct!($J))
    );
    ($I:expr, $J:expr, $($K:expr),+) => (
        {
            let it = iproduct!($I, $J);
            $(
                let it = $crate::misc::FlatTuples::new(iproduct!(it, $K));
            )*
            it
        }
    );
}

Create an iterator over the “cartesian product” of iterators.

Iterator element type is like (A, B, ..., E) if formed from iterators (I, J, ..., M) with element types I::Item = A, J::Item = B, etc.

#[macro_use]
extern crate itertools;
// Iterate over the coordinates of a 4 x 4 x 4 grid
// from (0, 0, 0), (0, 0, 1), .., (0, 1, 0), (0, 1, 1), .. etc until (3, 3, 3)
for (i, j, k) in iproduct!(0..4, 0..4, 0..4) {
   // ..
}