hetseq/
zip.rs

1use {List, Queue};
2
3
4pub trait Zip<S> {
5    ///
6    type Zipped;
7
8    ///
9    fn zip(self, S) -> Self::Zipped;
10}
11
12impl Zip<List<()>> for List<()> {
13    type Zipped = List<()>;
14
15    fn zip(self, _: List<()>) -> List<()> {
16        self
17    }
18}
19
20impl<LH, LT, RH, RT, ZT> Zip<List<(RH, RT)>> for List<(LH, LT)>
21    where LT: Zip<RT, Zipped = ZT>
22{
23    type Zipped = List<((LH, RH), ZT)>;
24
25    fn zip(self, right: List<(RH, RT)>) -> Self::Zipped {
26        let List((l_head, l_tail)) = self;
27        let List((r_head, r_tail)) = right;
28
29        List(((l_head, r_head), l_tail.zip(r_tail)))
30    }
31}
32
33impl Zip<Queue<()>> for Queue<()> {
34    type Zipped = Queue<()>;
35
36    fn zip(self, _: Queue<()>) -> Queue<()> {
37        self
38    }
39}
40
41impl<LH, LT, RH, RT, ZH> Zip<Queue<(RH, RT)>> for Queue<(LH, LT)>
42    where LH: Zip<RH, Zipped = ZH>
43{
44    type Zipped = Queue<(ZH, (LT, RT))>;
45
46    fn zip(self, right: Queue<(RH, RT)>) -> Self::Zipped {
47        let Queue((l_head, l_tail)) = self;
48        let Queue((r_head, r_tail)) = right;
49
50        Queue((l_head.zip(r_head), (l_tail, r_tail)))
51    }
52}