forked from functionaljava/functionaljava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathF2W.java
More file actions
254 lines (218 loc) · 7.76 KB
/
F2W.java
File metadata and controls
254 lines (218 loc) · 7.76 KB
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
package fj;
import fj.control.parallel.Promise;
import fj.data.*;
/**
* Created by MarkPerry on 22/01/2015.
*/
public abstract class F2W<A, B, C> implements F2<A, B, C> {
/**
* Partial application.
*
* @param a The <code>A</code> to which to apply this function.
* @return The function partially applied to the given argument.
*/
public final F1W<B, C> f(final A a) {
return F1W.lift(F2Functions.f(this, a));
}
/**
* Curries this wrapped function to a wrapped function of arity-1 that returns another wrapped function.
*
* @return a wrapped function of arity-1 that returns another wrapped function.
*/
public final F1W<A, F<B, C>> curry() {
return F1W.lift(F2Functions.curry(this));
}
/**
* Flips the arguments of this function.
*
* @return A new function with the arguments of this function flipped.
*/
public final F2W<B, A, C> flip() {
return lift(F2Functions.flip(this));
}
/**
* Uncurries this function to a function on tuples.
*
* @return A new function that calls this function with the elements of a given tuple.
*/
public final F1W<P2<A, B>, C> tuple() {
return F1W.lift(F2Functions.tuple(this));
}
/**
* Promotes this function to a function on Arrays.
*
* @return This function promoted to transform Arrays.
*/
public final F2W<Array<A>, Array<B>, Array<C>> arrayM() {
return lift(F2Functions.arrayM(this));
}
/**
* Promotes this function to a function on Promises.
*
* @return This function promoted to transform Promises.
*/
public final F2W<Promise<A>, Promise<B>, Promise<C>> promiseM() {
return lift(F2Functions.promiseM(this));
}
/**
* Promotes this function to a function on Iterables.
*
* @return This function promoted to transform Iterables.
*/
public final F2W<Iterable<A>, Iterable<B>, IterableW<C>> iterableM() {
return lift(F2Functions.iterableM(this));
}
/**
* Promotes this function to a function on Lists.
*
* @return This function promoted to transform Lists.
*/
public final F2W<List<A>, List<B>, List<C>> listM() {
return lift(F2Functions.listM(this));
}
/**
* Promotes this function to a function on non-empty lists.
*
* @return This function promoted to transform non-empty lists.
*/
public final F2W<NonEmptyList<A>, NonEmptyList<B>, NonEmptyList<C>> nelM() {
return lift(F2Functions.nelM(this));
}
/**
* Promotes this function to a function on Options.
*
* @return This function promoted to transform Options.
*/
public final F2W<Option<A>, Option<B>, Option<C>> optionM() {
return lift(F2Functions.optionM(this));
}
/**
* Promotes this function to a function on Sets.
*
* @param o An ordering for the result of the promoted function.
* @return This function promoted to transform Sets.
*/
public final F2W<Set<A>, Set<B>, Set<C>> setM(final Ord<C> o) {
return lift(F2Functions.setM(this, o));
}
/**
* Promotes this function to a function on Streams.
*
* @return This function promoted to transform Streams.
*/
public final F2W<Stream<A>, Stream<B>, Stream<C>> streamM() {
return lift(F2Functions.streamM(this));
}
/**
* Promotes this function to a function on Trees.
*
* @return This function promoted to transform Trees.
*/
public final F2W<Tree<A>, Tree<B>, Tree<C>> treeM() {
return lift(F2Functions.treeM(this));
}
/**
* Promotes this function to zip two arrays, applying the function lock-step over both Arrays.
*
* @return A function that zips two arrays with this function.
*/
public final F2W<Array<A>, Array<B>, Array<C>> zipArrayM() {
return lift(F2Functions.zipArrayM(this));
}
/**
* Promotes this function to zip two iterables, applying the function lock-step over both iterables.
*
* @return A function that zips two iterables with this function.
*/
public final F2W<Iterable<A>, Iterable<B>, Iterable<C>> zipIterableM() {
return lift(F2Functions.zipIterableM(this));
}
/**
* Promotes this function to zip two lists, applying the function lock-step over both lists.
*
* @return A function that zips two lists with this function.
*/
public final F2W<List<A>, List<B>, List<C>> zipListM() {
return lift(F2Functions.zipListM(this));
}
/**
* Promotes this function to zip two streams, applying the function lock-step over both streams.
*
* @return A function that zips two streams with this function.
*/
public final F2W<Stream<A>, Stream<B>, Stream<C>> zipStreamM() {
return lift(F2Functions.zipStreamM(this));
}
/**
* Promotes this function to zip two non-empty lists, applying the function lock-step over both lists.
*
* @return A function that zips two non-empty lists with this function.
*/
public final F2W<NonEmptyList<A>, NonEmptyList<B>, NonEmptyList<C>> zipNelM() {
return lift(F2Functions.zipNelM(this));
}
/**
* Promotes this function to zip two sets, applying the function lock-step over both sets.
*
* @param o An ordering for the resulting set.
* @return A function that zips two sets with this function.
*/
public final F2W<Set<A>, Set<B>, Set<C>> zipSetM(final Ord<C> o) {
return lift(F2Functions.zipSetM(this, o));
}
/**
* Promotes this function to zip two trees, applying the function lock-step over both trees.
* The structure of the resulting tree is the structural intersection of the two trees.
*
* @return A function that zips two trees with this function.
*/
public final F2W<Tree<A>, Tree<B>, Tree<C>> zipTreeM() {
return lift(F2Functions.zipTreeM(this));
}
/**
* Promotes this function to zip two zippers, applying the function lock-step over both zippers in both directions.
* The structure of the resulting zipper is the structural intersection of the two zippers.
*
* @return A function that zips two zippers with this function.
*/
public final F2W<Zipper<A>, Zipper<B>, Zipper<C>> zipZipperM() {
return lift(F2Functions.zipZipperM(this));
}
/**
* Promotes this function to zip two TreeZippers, applying the function lock-step over both zippers in all directions.
* The structure of the resulting TreeZipper is the structural intersection of the two TreeZippers.
*
* @return A function that zips two TreeZippers with this function.
*/
public final F2W<TreeZipper<A>, TreeZipper<B>, TreeZipper<C>> zipTreeZipperM() {
return lift(F2Functions.zipTreeZipperM(this));
}
public final <Z> F2W<Z, B, C> contramapFirst(F<Z, A> f) {
return lift(F2Functions.contramapFirst(this, f));
}
public final <Z> F2W<A, Z, C> contramapSecond(F<Z, B> f) {
return lift(F2Functions.contramapSecond(this, f));
}
public final <X, Y> F2W<X, Y, C> contramap(F<X, A> f, F<Y, B> g) {
return lift(F2Functions.contramap(this, f, g));
}
public final <Z> F2W<A, B, Z> map(F<C, Z> f) {
return lift(F2Functions.map(this, f));
}
public static class F2WFunc<A, B, C> extends F2W<A, B, C> {
final F2<A, B, C> func;
public F2WFunc(F2<A, B, C> f) {
func = f;
}
@Override
public final C f(A a, B b) {
return func.f(a, b);
}
}
/**
* Lifts the function into the fully featured function wrapper
*/
public static <A, B, C> F2W<A, B, C> lift(final F2<A, B, C> f) {
return new F2WFunc<>(f);
}
}