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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#![allow(clippy::many_single_char_names)]

use crate::impl_::dep::Dep;

pub struct Lambda<FN> {
    f: FN,
    deps: Vec<Dep>,
}

pub fn lambda1_deps<A, B, FN: IsLambda1<A, B>>(f: &FN) -> Vec<Dep> {
    f.deps_op().cloned().unwrap_or_default()
}

pub fn lambda2_deps<A, B, C, FN: IsLambda2<A, B, C>>(f: &FN) -> Vec<Dep> {
    f.deps_op().cloned().unwrap_or_default()
}

pub fn lambda3_deps<A, B, C, D, FN: IsLambda3<A, B, C, D>>(f: &FN) -> Vec<Dep> {
    f.deps_op().cloned().unwrap_or_default()
}

pub fn lambda4_deps<A, B, C, D, E, FN: IsLambda4<A, B, C, D, E>>(f: &FN) -> Vec<Dep> {
    f.deps_op().cloned().unwrap_or_default()
}

pub fn lambda5_deps<A, B, C, D, E, F, FN: IsLambda5<A, B, C, D, E, F>>(f: &FN) -> Vec<Dep> {
    f.deps_op().cloned().unwrap_or_default()
}

pub fn lambda6_deps<A, B, C, D, E, F, G, FN: IsLambda6<A, B, C, D, E, F, G>>(f: &FN) -> Vec<Dep> {
    f.deps_op().cloned().unwrap_or_default()
}

/// Interface for a lambda function of one argument.
pub trait IsLambda1<A, B> {
    fn call(&mut self, a: &A) -> B;
    fn deps_op(&self) -> Option<&Vec<Dep>>;
}

/// Interface for a lambda function of two arguments.
pub trait IsLambda2<A, B, C> {
    fn call(&mut self, a: &A, b: &B) -> C;
    fn deps_op(&self) -> Option<&Vec<Dep>>;
}

/// Interface for a lambda function of three arguments.
pub trait IsLambda3<A, B, C, D> {
    fn call(&mut self, a: &A, b: &B, c: &C) -> D;
    fn deps_op(&self) -> Option<&Vec<Dep>>;
}

/// Interface for a lambda function of four arguments.
pub trait IsLambda4<A, B, C, D, E> {
    fn call(&mut self, a: &A, b: &B, c: &C, d: &D) -> E;
    fn deps_op(&self) -> Option<&Vec<Dep>>;
}

/// Interface for a lambda function of five arguments.
pub trait IsLambda5<A, B, C, D, E, F> {
    fn call(&mut self, a: &A, b: &B, c: &C, d: &D, e: &E) -> F;
    fn deps_op(&self) -> Option<&Vec<Dep>>;
}

/// Interface for a lambda function of six arguments.
pub trait IsLambda6<A, B, C, D, E, F, G> {
    fn call(&mut self, a: &A, b: &B, c: &C, d: &D, e: &E, f: &F) -> G;
    fn deps_op(&self) -> Option<&Vec<Dep>>;
}

impl<A, B, FN: FnMut(&A) -> B> IsLambda1<A, B> for Lambda<FN> {
    fn call(&mut self, a: &A) -> B {
        (self.f)(a)
    }

    fn deps_op(&self) -> Option<&Vec<Dep>> {
        Some(&self.deps)
    }
}

impl<A, B, FN: FnMut(&A) -> B> IsLambda1<A, B> for FN {
    fn call(&mut self, a: &A) -> B {
        self(a)
    }

    fn deps_op(&self) -> Option<&Vec<Dep>> {
        None
    }
}

impl<A, B, C, FN: FnMut(&A, &B) -> C> IsLambda2<A, B, C> for Lambda<FN> {
    fn call(&mut self, a: &A, b: &B) -> C {
        (self.f)(a, b)
    }

    fn deps_op(&self) -> Option<&Vec<Dep>> {
        Some(&self.deps)
    }
}

impl<A, B, C, FN: FnMut(&A, &B) -> C> IsLambda2<A, B, C> for FN {
    fn call(&mut self, a: &A, b: &B) -> C {
        self(a, b)
    }

    fn deps_op(&self) -> Option<&Vec<Dep>> {
        None
    }
}

impl<A, B, C, D, FN: FnMut(&A, &B, &C) -> D> IsLambda3<A, B, C, D> for Lambda<FN> {
    fn call(&mut self, a: &A, b: &B, c: &C) -> D {
        (self.f)(a, b, c)
    }

    fn deps_op(&self) -> Option<&Vec<Dep>> {
        Some(&self.deps)
    }
}

impl<A, B, C, D, FN: FnMut(&A, &B, &C) -> D> IsLambda3<A, B, C, D> for FN {
    fn call(&mut self, a: &A, b: &B, c: &C) -> D {
        self(a, b, c)
    }

    fn deps_op(&self) -> Option<&Vec<Dep>> {
        None
    }
}

impl<A, B, C, D, E, FN: FnMut(&A, &B, &C, &D) -> E> IsLambda4<A, B, C, D, E> for Lambda<FN> {
    fn call(&mut self, a: &A, b: &B, c: &C, d: &D) -> E {
        (self.f)(a, b, c, d)
    }

    fn deps_op(&self) -> Option<&Vec<Dep>> {
        Some(&self.deps)
    }
}

impl<A, B, C, D, E, FN: FnMut(&A, &B, &C, &D) -> E> IsLambda4<A, B, C, D, E> for FN {
    fn call(&mut self, a: &A, b: &B, c: &C, d: &D) -> E {
        self(a, b, c, d)
    }

    fn deps_op(&self) -> Option<&Vec<Dep>> {
        None
    }
}

impl<A, B, C, D, E, F, FN: FnMut(&A, &B, &C, &D, &E) -> F> IsLambda5<A, B, C, D, E, F>
    for Lambda<FN>
{
    fn call(&mut self, a: &A, b: &B, c: &C, d: &D, e: &E) -> F {
        (self.f)(a, b, c, d, e)
    }

    fn deps_op(&self) -> Option<&Vec<Dep>> {
        Some(&self.deps)
    }
}

impl<A, B, C, D, E, F, FN: FnMut(&A, &B, &C, &D, &E) -> F> IsLambda5<A, B, C, D, E, F> for FN {
    fn call(&mut self, a: &A, b: &B, c: &C, d: &D, e: &E) -> F {
        self(a, b, c, d, e)
    }

    fn deps_op(&self) -> Option<&Vec<Dep>> {
        None
    }
}

impl<A, B, C, D, E, F, G, FN: FnMut(&A, &B, &C, &D, &E, &F) -> G> IsLambda6<A, B, C, D, E, F, G>
    for Lambda<FN>
{
    fn call(&mut self, a: &A, b: &B, c: &C, d: &D, e: &E, f: &F) -> G {
        (self.f)(a, b, c, d, e, f)
    }

    fn deps_op(&self) -> Option<&Vec<Dep>> {
        Some(&self.deps)
    }
}

impl<A, B, C, D, E, F, G, FN: FnMut(&A, &B, &C, &D, &E, &F) -> G> IsLambda6<A, B, C, D, E, F, G>
    for FN
{
    fn call(&mut self, a: &A, b: &B, c: &C, d: &D, e: &E, f: &F) -> G {
        self(a, b, c, d, e, f)
    }

    fn deps_op(&self) -> Option<&Vec<Dep>> {
        None
    }
}

pub fn lambda1<A, B, FN: FnMut(&A) -> B>(f: FN, deps: Vec<Dep>) -> Lambda<FN> {
    Lambda { f, deps }
}

pub fn lambda2<A, B, C, FN: FnMut(&A, &B) -> C>(f: FN, deps: Vec<Dep>) -> Lambda<FN> {
    Lambda { f, deps }
}

pub fn lambda3<A, B, C, D, FN: FnMut(&A, &B, &C) -> D>(f: FN, deps: Vec<Dep>) -> Lambda<FN> {
    Lambda { f, deps }
}

pub fn lambda4<A, B, C, D, E, FN: FnMut(&A, &B, &C, &D) -> E>(f: FN, deps: Vec<Dep>) -> Lambda<FN> {
    Lambda { f, deps }
}

pub fn lambda5<A, B, C, D, E, F, FN: FnMut(&A, &B, &C, &D, &E) -> F>(
    f: FN,
    deps: Vec<Dep>,
) -> Lambda<FN> {
    Lambda { f, deps }
}

pub fn lambda6<A, B, C, D, E, F, G, FN: FnMut(&A, &B, &C, &D, &E, &F) -> G>(
    f: FN,
    deps: Vec<Dep>,
) -> Lambda<FN> {
    Lambda { f, deps }
}