macro_rules! cartesian_product {
    ($I:expr $(,)?) => { ... };
    ($I:expr, $J:expr $(,)?) => { ... };
    ($I:expr, $J:expr, $($K:expr),+ $(,)?) => { ... };
}
Available on crate feature cartesian_product only.
Expand description

Returns an iterator over the cartesian product of the element sets of multiple iterators (up to 12).

This is essentially the equivalent of calling cartesian_product multiple times and ā€œflatteningā€ each item e.g. ((A, B), C) to (A, B, C).

Examples

use itermore::{cartesian_product, IterCartesianProduct};

// With macro
let i = cartesian_product!(0..3, "Ī±Ī²".chars(), [-1, 0, 1]);

// Without macro
let j = (0..3)
    .cartesian_product("Ī±Ī²".chars())
    .cartesian_product([-1, 0, 1])
    .map(|((a, b), c)| (a, b, c));

assert_eq!(Vec::from_iter(i), Vec::from_iter(j));

Iterate over the 3D coordinates of a 10 x 10 x 10 cube.

use itermore::cartesian_product;

// With macro
for (i, j, k) in cartesian_product!(0..10, 0..10, 0..10) {
    // ...
}

// Without macro
for i in 0..10 {
    for j in 0..10 {
        for k in 0..10 {
            // ...
        }
    }
}