0
|
1 package fj;
|
|
2
|
|
3 /**
|
|
4 * A product-4.
|
|
5 *
|
|
6 * @version %build.number%
|
|
7 */
|
|
8 public abstract class P4<A, B, C, D> {
|
|
9 /**
|
|
10 * Access the first element of the product.
|
|
11 *
|
|
12 * @return The first element of the product.
|
|
13 */
|
|
14 public abstract A _1();
|
|
15
|
|
16 /**
|
|
17 * Access the second element of the product.
|
|
18 *
|
|
19 * @return The second element of the product.
|
|
20 */
|
|
21 public abstract B _2();
|
|
22
|
|
23 /**
|
|
24 * Access the third element of the product.
|
|
25 *
|
|
26 * @return The third element of the product.
|
|
27 */
|
|
28 public abstract C _3();
|
|
29
|
|
30 /**
|
|
31 * Access the fourth element of the product.
|
|
32 *
|
|
33 * @return The fourth element of the product.
|
|
34 */
|
|
35 public abstract D _4();
|
|
36
|
|
37 /**
|
|
38 * Map the first element of the product.
|
|
39 *
|
|
40 * @param f The function to map with.
|
|
41 * @return A product with the given function applied.
|
|
42 */
|
|
43 public final <X> P4<X, B, C, D> map1(final F<A, X> f) {
|
|
44 return new P4<X, B, C, D>() {
|
|
45 public X _1() {
|
|
46 return f.f(P4.this._1());
|
|
47 }
|
|
48
|
|
49 public B _2() {
|
|
50 return P4.this._2();
|
|
51 }
|
|
52
|
|
53 public C _3() {
|
|
54 return P4.this._3();
|
|
55 }
|
|
56
|
|
57 public D _4() {
|
|
58 return P4.this._4();
|
|
59 }
|
|
60 };
|
|
61 }
|
|
62
|
|
63 /**
|
|
64 * Map the second element of the product.
|
|
65 *
|
|
66 * @param f The function to map with.
|
|
67 * @return A product with the given function applied.
|
|
68 */
|
|
69 public final <X> P4<A, X, C, D> map2(final F<B, X> f) {
|
|
70 return new P4<A, X, C, D>() {
|
|
71 public A _1() {
|
|
72 return P4.this._1();
|
|
73 }
|
|
74
|
|
75 public X _2() {
|
|
76 return f.f(P4.this._2());
|
|
77 }
|
|
78
|
|
79 public C _3() {
|
|
80 return P4.this._3();
|
|
81 }
|
|
82
|
|
83 public D _4() {
|
|
84 return P4.this._4();
|
|
85 }
|
|
86 };
|
|
87 }
|
|
88
|
|
89 /**
|
|
90 * Map the third element of the product.
|
|
91 *
|
|
92 * @param f The function to map with.
|
|
93 * @return A product with the given function applied.
|
|
94 */
|
|
95 public final <X> P4<A, B, X, D> map3(final F<C, X> f) {
|
|
96 return new P4<A, B, X, D>() {
|
|
97 public A _1() {
|
|
98 return P4.this._1();
|
|
99 }
|
|
100
|
|
101 public B _2() {
|
|
102 return P4.this._2();
|
|
103 }
|
|
104
|
|
105 public X _3() {
|
|
106 return f.f(P4.this._3());
|
|
107 }
|
|
108
|
|
109 public D _4() {
|
|
110 return P4.this._4();
|
|
111 }
|
|
112 };
|
|
113 }
|
|
114
|
|
115 /**
|
|
116 * Map the fourth element of the product.
|
|
117 *
|
|
118 * @param f The function to map with.
|
|
119 * @return A product with the given function applied.
|
|
120 */
|
|
121 public final <X> P4<A, B, C, X> map4(final F<D, X> f) {
|
|
122 return new P4<A, B, C, X>() {
|
|
123 public A _1() {
|
|
124 return P4.this._1();
|
|
125 }
|
|
126
|
|
127 public B _2() {
|
|
128 return P4.this._2();
|
|
129 }
|
|
130
|
|
131 public C _3() {
|
|
132 return P4.this._3();
|
|
133 }
|
|
134
|
|
135 public X _4() {
|
|
136 return f.f(P4.this._4());
|
|
137 }
|
|
138 };
|
|
139 }
|
|
140
|
|
141 /**
|
|
142 * Returns the 1-product projection over the first element.
|
|
143 *
|
|
144 * @return the 1-product projection over the first element.
|
|
145 */
|
|
146 public final P1<A> _1_() {
|
|
147 return F1Functions.lazy(P4.<A, B, C, D>__1()).f(this);
|
|
148 }
|
|
149
|
|
150 /**
|
|
151 * Returns the 1-product projection over the second element.
|
|
152 *
|
|
153 * @return the 1-product projection over the second element.
|
|
154 */
|
|
155 public final P1<B> _2_() {
|
|
156 return F1Functions.lazy(P4.<A, B, C, D>__2()).f(this);
|
|
157 }
|
|
158
|
|
159 /**
|
|
160 * Returns the 1-product projection over the third element.
|
|
161 *
|
|
162 * @return the 1-product projection over the third element.
|
|
163 */
|
|
164 public final P1<C> _3_() {
|
|
165 return F1Functions.lazy(P4.<A, B, C, D>__3()).f(this);
|
|
166 }
|
|
167
|
|
168 /**
|
|
169 * Returns the 1-product projection over the fourth element.
|
|
170 *
|
|
171 * @return the 1-product projection over the fourth element.
|
|
172 */
|
|
173 public final P1<D> _4_() {
|
|
174 return F1Functions.lazy(P4.<A, B, C, D>__4()).f(this);
|
|
175 }
|
|
176
|
|
177 /**
|
|
178 * Provides a memoising P4 that remembers its values.
|
|
179 *
|
|
180 * @return A P4 that calls this P4 once for any given element and remembers the value for subsequent calls.
|
|
181 */
|
|
182 public final P4<A, B, C, D> memo() {
|
|
183 P4<A, B, C, D> self = this;
|
|
184 return new P4<A, B, C, D>() {
|
|
185 private final P1<A> a = P1.memo(u -> self._1());
|
|
186 private final P1<B> b = P1.memo(u -> self._2());
|
|
187 private final P1<C> c = P1.memo(u -> self._3());
|
|
188 private final P1<D> d = P1.memo(u -> self._4());
|
|
189
|
|
190 public A _1() {
|
|
191 return a._1();
|
|
192 }
|
|
193
|
|
194 public B _2() {
|
|
195 return b._1();
|
|
196 }
|
|
197
|
|
198 public C _3() {
|
|
199 return c._1();
|
|
200 }
|
|
201
|
|
202 public D _4() {
|
|
203 return d._1();
|
|
204 }
|
|
205 };
|
|
206 }
|
|
207
|
|
208
|
|
209 /**
|
|
210 * Returns a function that returns the first element of a product.
|
|
211 *
|
|
212 * @return A function that returns the first element of a product.
|
|
213 */
|
|
214 public static <A, B, C, D> F<P4<A, B, C, D>, A> __1() {
|
|
215 return new F<P4<A, B, C, D>, A>() {
|
|
216 public A f(final P4<A, B, C, D> p) {
|
|
217 return p._1();
|
|
218 }
|
|
219 };
|
|
220 }
|
|
221
|
|
222 /**
|
|
223 * Returns a function that returns the second element of a product.
|
|
224 *
|
|
225 * @return A function that returns the second element of a product.
|
|
226 */
|
|
227 public static <A, B, C, D> F<P4<A, B, C, D>, B> __2() {
|
|
228 return new F<P4<A, B, C, D>, B>() {
|
|
229 public B f(final P4<A, B, C, D> p) {
|
|
230 return p._2();
|
|
231 }
|
|
232 };
|
|
233 }
|
|
234
|
|
235 /**
|
|
236 * Returns a function that returns the third element of a product.
|
|
237 *
|
|
238 * @return A function that returns the third element of a product.
|
|
239 */
|
|
240 public static <A, B, C, D> F<P4<A, B, C, D>, C> __3() {
|
|
241 return new F<P4<A, B, C, D>, C>() {
|
|
242 public C f(final P4<A, B, C, D> p) {
|
|
243 return p._3();
|
|
244 }
|
|
245 };
|
|
246 }
|
|
247
|
|
248 /**
|
|
249 * Returns a function that returns the fourth element of a product.
|
|
250 *
|
|
251 * @return A function that returns the fourth element of a product.
|
|
252 */
|
|
253 public static <A, B, C, D> F<P4<A, B, C, D>, D> __4() {
|
|
254 return new F<P4<A, B, C, D>, D>() {
|
|
255 public D f(final P4<A, B, C, D> p) {
|
|
256 return p._4();
|
|
257 }
|
|
258 };
|
|
259 }
|
|
260
|
|
261 public String toString() {
|
|
262 return Show.p4Show(Show.<A>anyShow(), Show.<B>anyShow(), Show.<C>anyShow(), Show.<D>anyShow()).showS(this);
|
|
263 }
|
|
264
|
|
265 }
|