-
Notifications
You must be signed in to change notification settings - Fork 1
/
functional.go
193 lines (175 loc) · 3.68 KB
/
functional.go
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
package ranges
func Compose2[A, B, C any](f1 func(x B) C, f2 func(x A) B) func(x A) C {
return func(x A) C { return f1(f2(x)) }
}
func Compose3[A, B, C, D any](
f1 func(x C) D,
f2 func(x B) C,
f3 func(x A) B,
) func(x A) D {
return Compose2(Compose2(f1, f2), f3)
}
func Compose4[A, B, C, D, E any](
f1 func(x D) E,
f2 func(x C) D,
f3 func(x B) C,
f4 func(x A) B,
) func(x A) E {
return Compose2(Compose3(f1, f2, f3), f4)
}
func Compose5[A, B, C, D, E, F any](
f1 func(x E) F,
f2 func(x D) E,
f3 func(x C) D,
f4 func(x B) C,
f5 func(x A) B,
) func(x A) F {
return Compose2(Compose4(f1, f2, f3, f4), f5)
}
func Compose6[A, B, C, D, E, F, G any](
f1 func(x F) G,
f2 func(x E) F,
f3 func(x D) E,
f4 func(x C) D,
f5 func(x B) C,
f6 func(x A) B,
) func(x A) G {
return Compose2(Compose5(f1, f2, f3, f4, f5), f6)
}
func Compose7[A, B, C, D, E, F, G, H any](
f1 func(x G) H,
f2 func(x F) G,
f3 func(x E) F,
f4 func(x D) E,
f5 func(x C) D,
f6 func(x B) C,
f7 func(x A) B,
) func(x A) H {
return Compose2(Compose6(f1, f2, f3, f4, f5, f6), f7)
}
func Compose8[A, B, C, D, E, F, G, H, I any](
f1 func(x H) I,
f2 func(x G) H,
f3 func(x F) G,
f4 func(x E) F,
f5 func(x D) E,
f6 func(x C) D,
f7 func(x B) C,
f8 func(x A) B,
) func(x A) I {
return Compose2(Compose7(f1, f2, f3, f4, f5, f6, f7), f8)
}
func Compose9[A, B, C, D, E, F, G, H, I, J any](
f1 func(x I) J,
f2 func(x H) I,
f3 func(x G) H,
f4 func(x F) G,
f5 func(x E) F,
f6 func(x D) E,
f7 func(x C) D,
f8 func(x B) C,
f9 func(x A) B,
) func(x A) J {
return Compose2(Compose8(f1, f2, f3, f4, f5, f6, f7, f8), f9)
}
func Compose10[A, B, C, D, E, F, G, H, I, J, K any](
f1 func(x J) K,
f2 func(x I) J,
f3 func(x H) I,
f4 func(x G) H,
f5 func(x F) G,
f6 func(x E) F,
f7 func(x D) E,
f8 func(x C) D,
f9 func(x B) C,
f10 func(x A) B,
) func(x A) K {
return Compose2(Compose9(f1, f2, f3, f4, f5, f6, f7, f8, f9), f10)
}
func Pipe2[A, B, C any](f1 func(x A) B, f2 func(x B) C) func(x A) C {
return func(x A) C { return f2(f1(x)) }
}
func Pipe3[A, B, C, D any](
f1 func(x A) B,
f2 func(x B) C,
f3 func(x C) D,
) func(x A) D {
return Pipe2(Pipe2(f1, f2), f3)
}
func Pipe4[A, B, C, D, E any](
f1 func(x A) B,
f2 func(x B) C,
f3 func(x C) D,
f4 func(x D) E,
) func(x A) E {
return Pipe2(Pipe3(f1, f2, f3), f4)
}
func Pipe5[A, B, C, D, E, F any](
f1 func(x A) B,
f2 func(x B) C,
f3 func(x C) D,
f4 func(x D) E,
f5 func(x E) F,
) func(x A) F {
return Pipe2(Pipe4(f1, f2, f3, f4), f5)
}
func Pipe6[A, B, C, D, E, F, G any](
f1 func(x A) B,
f2 func(x B) C,
f3 func(x C) D,
f4 func(x D) E,
f5 func(x E) F,
f6 func(x F) G,
) func(x A) G {
return Pipe2(Pipe5(f1, f2, f3, f4, f5), f6)
}
func Pipe7[A, B, C, D, E, F, G, H any](
f1 func(x A) B,
f2 func(x B) C,
f3 func(x C) D,
f4 func(x D) E,
f5 func(x E) F,
f6 func(x F) G,
f7 func(x G) H,
) func(x A) H {
return Pipe2(Pipe6(f1, f2, f3, f4, f5, f6), f7)
}
func Pipe8[A, B, C, D, E, F, G, H, I any](
f1 func(x A) B,
f2 func(x B) C,
f3 func(x C) D,
f4 func(x D) E,
f5 func(x E) F,
f6 func(x F) G,
f7 func(x G) H,
f8 func(x H) I,
) func(x A) I {
return Pipe2(Pipe7(f1, f2, f3, f4, f5, f6, f7), f8)
}
func Pipe9[A, B, C, D, E, F, G, H, I, J any](
f1 func(x A) B,
f2 func(x B) C,
f3 func(x C) D,
f4 func(x D) E,
f5 func(x E) F,
f6 func(x F) G,
f7 func(x G) H,
f8 func(x H) I,
f9 func(x I) J,
) func(x A) J {
return Pipe2(Pipe8(f1, f2, f3, f4, f5, f6, f7, f8), f9)
}
func Pipe10[A, B, C, D, E, F, G, H, I, J, K any](
f1 func(x A) B,
f2 func(x B) C,
f3 func(x C) D,
f4 func(x D) E,
f5 func(x E) F,
f6 func(x F) G,
f7 func(x G) H,
f8 func(x H) I,
f9 func(x I) J,
f10 func(x J) K,
) func(x A) K {
return Pipe2(Pipe9(f1, f2, f3, f4, f5, f6, f7, f8, f9), f10)
}