1 use crate::adaptors::map::{MapSpecialCase, MapSpecialCaseFn};
2
3 macro_rules! impl_cons_iter(
4 ($_A:ident, $_B:ident, ) => (); // stop
5
6 ($A:ident, $($B:ident,)*) => (
7 impl_cons_iter!($($B,)*);
8 #[allow(non_snake_case)]
9 impl<$($B),*, X> MapSpecialCaseFn<(($($B,)*), X)> for ConsTuplesFn {
10 type Out = ($($B,)* X, );
11 fn call(&mut self, (($($B,)*), X): (($($B,)*), X)) -> Self::Out {
12 ($($B,)* X, )
13 }
14 }
15 );
16 );
17
18 impl_cons_iter!(A, B, C, D, E, F, G, H, I, J, K, L,);
19
20 #[derive(Debug, Clone)]
21 pub struct ConsTuplesFn;
22
23 /// An iterator that maps an iterator of tuples like
24 /// `((A, B), C)` to an iterator of `(A, B, C)`.
25 ///
26 /// Used by the `iproduct!()` macro.
27 pub type ConsTuples<I> = MapSpecialCase<I, ConsTuplesFn>;
28
29 /// Create an iterator that maps for example iterators of
30 /// `((A, B), C)` to `(A, B, C)`.
cons_tuples<I>(iterable: I) -> ConsTuples<I::IntoIter> where I: IntoIterator,31 pub fn cons_tuples<I>(iterable: I) -> ConsTuples<I::IntoIter>
32 where
33 I: IntoIterator,
34 {
35 ConsTuples {
36 iter: iterable.into_iter(),
37 f: ConsTuplesFn,
38 }
39 }
40