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
use sodium::Dep;
pub struct Lambda<FN: ?Sized> {
apply: Box<FN>,
deps: Vec<Dep>
}
impl<FN> Lambda<FN> {
pub fn new(apply: FN, deps: Vec<Dep>) -> Lambda<FN> {
Lambda {
apply: Box::new(apply),
deps: deps
}
}
pub fn add_deps(&mut self, mut deps: Vec<Dep>) {
self.deps.append(&mut deps);
}
pub fn add_deps_tunneled(mut self, deps: Vec<Dep>) -> Lambda<FN> {
self.add_deps(deps);
self
}
}
macro_rules! lambda {
($f:expr) => {{
Lambda::new($f, Vec::new())
}};
($f:expr, $($deps:expr),*) => {{
Lambda::new($f, vec![$($deps,)*])
}}
}
pub trait IsLambda0<R> {
fn apply(&self) -> R;
fn deps(&self) -> Vec<Dep>;
}
pub trait IsLambda1<A,R> {
fn apply(&self, a: &A) -> R;
fn deps(&self) -> Vec<Dep>;
}
pub trait IsLambda2<A,B,R> {
fn apply(&self, a: &A, b: &B) -> R;
fn deps(&self) -> Vec<Dep>;
}
pub trait IsLambda3<A,B,C,R> {
fn apply(&self, a: &A, b: &B, c: &C) -> R;
fn deps(&self) -> Vec<Dep>;
}
pub trait IsLambda4<A,B,C,D,R> {
fn apply(&self, a: &A, b: &B, c: &C, d: &D) -> R;
fn deps(&self) -> Vec<Dep>;
}
pub trait IsLambda5<A,B,C,D,E,R> {
fn apply(&self, a: &A, b: &B, c: &C, d: &D, e: &E) -> R;
fn deps(&self) -> Vec<Dep>;
}
pub trait IsLambda6<A,B,C,D,E,F,R> {
fn apply(&self, a: &A, b: &B, c: &C, d: &D, e: &E, f: &F) -> R;
fn deps(&self) -> Vec<Dep>;
}
impl<R,FN:Fn()->R> IsLambda0<R> for FN {
fn apply(&self) -> R {
self()
}
fn deps(&self) -> Vec<Dep> {
Vec::new()
}
}
impl<A,R,FN:Fn(&A)->R> IsLambda1<A,R> for FN {
fn apply(&self, a: &A) -> R {
self(a)
}
fn deps(&self) -> Vec<Dep> {
Vec::new()
}
}
impl<A,B,R,FN:Fn(&A,&B)->R> IsLambda2<A,B,R> for FN {
fn apply(&self, a: &A, b: &B) -> R {
self(a, b)
}
fn deps(&self) -> Vec<Dep> {
Vec::new()
}
}
impl<A,B,C,R,FN:Fn(&A,&B,&C)->R> IsLambda3<A,B,C,R> for FN {
fn apply(&self, a: &A, b: &B, c: &C) -> R {
self(a, b, c)
}
fn deps(&self) -> Vec<Dep> {
Vec::new()
}
}
impl<A,B,C,D,R,FN:Fn(&A,&B,&C,&D)->R> IsLambda4<A,B,C,D,R> for FN {
fn apply(&self, a: &A, b: &B, c: &C, d: &D) -> R {
self(a, b, c, d)
}
fn deps(&self) -> Vec<Dep> {
Vec::new()
}
}
impl<A,B,C,D,E,R,FN:Fn(&A,&B,&C,&D,&E)->R> IsLambda5<A,B,C,D,E,R> for FN {
fn apply(&self, a: &A, b: &B, c: &C, d: &D, e: &E) -> R {
self(a, b, c, d, e)
}
fn deps(&self) -> Vec<Dep> {
Vec::new()
}
}
impl<A,B,C,D,E,F,R,FN:Fn(&A,&B,&C,&D,&E,&F)->R> IsLambda6<A,B,C,D,E,F,R> for FN {
fn apply(&self, a: &A, b: &B, c: &C, d: &D, e: &E, f: &F) -> R {
self(a, b, c, d, e, f)
}
fn deps(&self) -> Vec<Dep> {
Vec::new()
}
}
impl<R,FN:Fn()->R> IsLambda0<R> for Lambda<FN> {
fn apply(&self) -> R {
(self.apply)()
}
fn deps(&self) -> Vec<Dep> {
self.deps.clone()
}
}
impl<A,R,FN:Fn(&A)->R> IsLambda1<A,R> for Lambda<FN> {
fn apply(&self, a: &A) -> R {
(self.apply)(a)
}
fn deps(&self) -> Vec<Dep> {
self.deps.clone()
}
}
impl<A,B,R,FN:Fn(&A,&B)->R> IsLambda2<A,B,R> for Lambda<FN> {
fn apply(&self, a: &A, b: &B) -> R {
(self.apply)(a, b)
}
fn deps(&self) -> Vec<Dep> {
self.deps.clone()
}
}
impl<A,B,C,R,FN:Fn(&A,&B,&C)->R> IsLambda3<A,B,C,R> for Lambda<FN> {
fn apply(&self, a: &A, b: &B, c: &C) -> R {
(self.apply)(a, b, c)
}
fn deps(&self) -> Vec<Dep> {
self.deps.clone()
}
}
impl<A,B,C,D,R,FN:Fn(&A,&B,&C,&D)->R> IsLambda4<A,B,C,D,R> for Lambda<FN> {
fn apply(&self, a: &A, b: &B, c: &C, d: &D) -> R {
(self.apply)(a, b, c, d)
}
fn deps(&self) -> Vec<Dep> {
self.deps.clone()
}
}
impl<A,B,C,D,E,R,FN:Fn(&A,&B,&C,&D,&E)->R> IsLambda5<A,B,C,D,E,R> for Lambda<FN> {
fn apply(&self, a: &A, b: &B, c: &C, d: &D, e: &E) -> R {
(self.apply)(a, b, c, d, e)
}
fn deps(&self) -> Vec<Dep> {
self.deps.clone()
}
}
impl<A,B,C,D,E,F,R,FN:Fn(&A,&B,&C,&D,&E,&F)->R> IsLambda6<A,B,C,D,E,F,R> for Lambda<FN> {
fn apply(&self, a: &A, b: &B, c: &C, d: &D, e: &E, f: &F) -> R {
(self.apply)(a, b, c, d, e, f)
}
fn deps(&self) -> Vec<Dep> {
self.deps.clone()
}
}