1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use super::{Grid2, Grid3, Grid4, IntoGrid};
use crate::combine::combine;
use itertools::Itertools;

impl<I1, I2> IntoGrid for (I1, I2)
where
    I1: Iterator + Itertools,
    I1::Item: Clone,
    I2: Iterator + Clone,
{
    type Grid = Grid2<I1, I2>;
    fn into_grid(self) -> Self::Grid {
        self.0.cartesian_product(self.1)
    }
}

impl<I1, I2, I3> IntoGrid for (I1, I2, I3)
where
    I1: Iterator + Itertools,
    I1::Item: Clone,
    I2: Iterator + Clone,
    I2::Item: Clone,
    I3: Iterator + Clone,
{
    type Grid = Grid3<I1, I2, I3>;
    fn into_grid(self) -> Self::Grid {
        combine((self.0, self.1).into_grid().cartesian_product(self.2))
    }
}

impl<I1, I2, I3, I4> IntoGrid for (I1, I2, I3, I4)
where
    I1: Iterator + Itertools,
    I1::Item: Clone,
    I2: Iterator + Clone,
    I2::Item: Clone,
    I3: Iterator + Clone,
    I3::Item: Clone,
    I4: Iterator + Clone,
{
    type Grid = Grid4<I1, I2, I3, I4>;
    fn into_grid(self) -> Self::Grid {
        combine(
            combine((self.0, self.1).into_grid().cartesian_product(self.2))
                .cartesian_product(self.3),
        )
    }
}