[no description]
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
use std::fs::File;
use std::io::Write;
use std::path::Path;

fn main() {
    let e = std::env::var("OUT_DIR").unwrap();
    let mut impl_td =
        File::create(Path::new(&e).join("impl_td.rs")).unwrap();
    let mut impl_rv =
        File::create(Path::new(&e).join("impl_rv.rs")).unwrap();
    let mut impl_pk =
        File::create(Path::new(&e).join("impl_pk.rs")).unwrap();
    let mut impl_mp =
        File::create(Path::new(&e).join("impl_mp.rs")).unwrap();

    for n in 0..26 {
        let z = ('A'..='Z').take(n).collect::<Vec<_>>().into_iter();
        generate(
            z,
            &mut impl_td,
            &mut impl_rv,
            &mut impl_pk,
            &mut impl_mp,
        );
    }
}
fn tup<D: std::fmt::Display>(x: impl Iterator<Item = D>) -> String {
    let mut s = String::default();
    for lem in x {
        use std::fmt::Write;
        write!(&mut s, "{lem}").unwrap();
        s.push(',');
    }

    s
}
fn generate(
    x: impl Iterator<Item = char>
    + Clone
    + DoubleEndedIterator
    + ExactSizeIterator,
    impl_td: &mut impl Write,
    impl_rv: &mut impl Write,
    impl_pk: &mut impl Write,
    impl_mp: &mut impl Write,
) {
    let tupl = tup(x.clone());
    let n = x.clone().count();
    for i in 0..n.min(10) {
        let drop = tup(x.clone().skip(i));
        let take = tup(x.clone().take(i));
        let take_b = tup(x.clone().rev().take(i).rev());
        let drop_b = tup(x.clone().rev().skip(i).rev());
        write!(
            impl_td,
            "
    impl<{tupl}> TD<{i}> for ({tupl}) {{
        type Drop = ({drop});
        type Take = ({take});
        type TakeB = ({take_b});
        type DropB = ({drop_b});
        
        fn dropf(self) -> (Self::Take, Self::Drop) {{
            let ({tupl}) = self;
            (({take}), ({drop}))
        }}
        
        fn dropb(self) -> (Self::DropB, Self::TakeB) {{
            let ({tupl}) = self;
            (({drop_b}), ({take_b}))
        }}
    }}
    ",
        )
        .unwrap();

        write!(
            impl_pk,
            "
    impl<{tupl}> Pick<{i}> for ({tupl}) {{
        type At = {at};
        type L = ({left});
        type R = ({right});
        type Delete = ({left} /* */ {right});
        fn delete(({left}): Self::L, ({right}): Self::R) -> Self::Delete \
             {{ 
            ({left} {right})
        }}
        fn repick(({left}): Self::L, at: Self::At, ({right}): Self::R) -> \
             Self {{
            ({left} at, {right})
        }}
        fn depict(self) -> (Self::L, Self::At, Self::R) {{
            let ({tupl}) = self;
            (({left}), {at}, ({right}))
        }}
    }}
    
        impl<{tupl} Z> RePick<{i}, Z> for ({tupl}) {{
        type New = ({left} Z, {right});
        fn unpick(({left}): Self::L, at: Z, ({right}): Self::R) -> \
             Self::New {{
            ({left} at, {right})
        }}
    }}
    ",
            at = x.clone().nth(i).unwrap(),
            left = tup(x.clone().take(i)),
            right = tup(x.clone().skip(i + 1))
        )
        .unwrap();
    }
    let rev = tup(x.clone().rev());
    write!(
        impl_rv,
        "
    #[allow(non_snake_case)]
    impl<{tupl}> Reverse for ({tupl}) {{
        type Reversed = ({rev});
        
        fn reverse(self) -> Self::Reversed {{
            let ({tupl}) = self;
            ({rev})
        }}
    }}
    ",
    )
    .unwrap();
    write!(
        impl_mp,
        // type Fns = ({fns_});
        // type Mapped = ({lowr});
        "
        impl<{tupl} {ret} {fns}> MapAll<({ret}), ({fns_})> for ({tupl}) \
         {{            
            fn map_all(self, ({ret}): ({fns_})) -> ({ret}) {{
                let ({tupl}) = self;
                ({mapped})
            }}
        }}
        impl<{tupl} {ret} {fns2}> MapAllMut<({ret}), ({fns_})> for \
         ({tupl}) {{            
            fn map_all_mut(self, x: &mut ({fns_})) -> ({ret}) {{
                MapAll::map_all(self, x.as_mut())
            }}
        }}
    ",
        ret = tup(x.clone().map(|x| format!("R{x}"))),
        fns_ = tup(x.clone().map(|x| format!("F{x}"))),
        fns = tup(x.clone().map(|x| format!("F{x}:FnOnce({x}) -> R{x}",))),
        fns2 = tup(x.clone().map(|x| format!("F{x}:FnMut({x}) -> R{x}",))),
        mapped = tup(x.clone().map(|x| format!("R{}({x})", x)))
    )
    .unwrap();
}