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
49
50
51
52
53
54
use crate::map::{Map, Function};
pub type Combine<I> = Map<I, CombineFn>;
pub fn combine<I>(iter: I) -> Combine<<I as IntoIterator>::IntoIter>
where
I: IntoIterator,
{
Map::new(iter, CombineFn)
}
pub struct CombineFn;
impl<A, B, C> Function<((A, B), C)> for CombineFn {
type Output = (A, B, C);
#[inline]
fn call(&self, ((a, b), c): ((A, B), C)) -> Self::Output {
(a, b, c)
}
}
impl<A, B, C, D> Function<((A, B, C), D)> for CombineFn {
type Output = (A, B, C, D);
#[inline]
fn call(&self, ((a, b, c), d): ((A, B, C), D)) -> Self::Output {
(a, b, c, d)
}
}
#[cfg(test)]
mod tests {
use super::combine;
#[test]
fn test_combine() {
let it = combine(vec![
((0, 1), 2),
((3, 4), 5),
]);
assert!(it.eq(vec![
(0, 1, 2),
(3, 4, 5),
]));
}
}