Skip to content

Commit 065ed43

Browse files
janbolsjbgi
authored andcommitted
Add append methods to all Px classes. Fix #326
1 parent 40fc161 commit 065ed43

File tree

6 files changed

+218
-1
lines changed

6 files changed

+218
-1
lines changed

core/src/main/java/fj/P2.java

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,68 @@ public final P1<B> _2_() {
178178
return F1Functions.lazy(P2.<A, B>__2()).f(this);
179179
}
180180

181-
/**
181+
/**
182+
* Creates a {@link P3} by adding the given element to the current {@link P2}
183+
*
184+
* @param el the element to append
185+
* @return A {@link P3} containing the original {@link P2} with the extra element added at the end
186+
*/
187+
public final <C> P3<A, B, C> append(C el) {
188+
return P.p(_1(), _2(), el);
189+
}
190+
191+
/**
192+
* Creates a {@link P4} by adding the given element to the current {@link P2}
193+
*
194+
* @param el the element to append
195+
* @return A {@link P4} containing the original {@link P2} with the extra element added at the end
196+
*/
197+
public final <C, D> P4<A, B, C, D> append(P2<C, D> el) {
198+
return P.p(_1(), _2(), el._1(), el._2());
199+
}
200+
201+
/**
202+
* Creates a {@link P5} by adding the given element to the current {@link P2}
203+
*
204+
* @param el the element to append
205+
* @return A {@link P5} containing the original {@link P2} with the extra element added at the end
206+
*/
207+
public final <C, D, E> P5<A, B, C, D, E> append(P3<C, D, E> el) {
208+
return P.p(_1(), _2(), el._1(), el._2(), el._3());
209+
}
210+
211+
/**
212+
* Creates a {@link P6} by adding the given element to the current {@link P2}
213+
*
214+
* @param el the element to append
215+
* @return A {@link P6} containing the original {@link P2} with the extra element added at the end
216+
*/
217+
public final <C, D, E, F> P6<A, B, C, D, E, F> append(P4<C, D, E, F> el) {
218+
return P.p(_1(), _2(), el._1(), el._2(), el._3(), el._4());
219+
}
220+
221+
/**
222+
* Creates a {@link P7} by adding the given element to the current {@link P2}
223+
*
224+
* @param el the element to append
225+
* @return A {@link P7} containing the original {@link P2} with the extra element added at the end
226+
*/
227+
public final <C, D, E, F, G> P7<A, B, C, D, E, F, G> append(P5<C, D, E, F, G> el) {
228+
return P.p(_1(), _2(), el._1(), el._2(), el._3(), el._4(), el._5());
229+
}
230+
231+
/**
232+
* Creates a {@link P8} by adding the given element to the current {@link P2}
233+
*
234+
* @param el the element to append
235+
* @return A {@link P8} containing the original {@link P2} with the extra element added at the end
236+
*/
237+
public final <C, D, E, F, G, H> P8<A, B, C, D, E, F, G, H> append(P6<C, D, E, F, G, H> el) {
238+
return P.p(_1(), _2(), el._1(), el._2(), el._3(), el._4(), el._5(), el._6());
239+
}
240+
241+
242+
/**
182243
* Provides a memoising P2 that remembers its values.
183244
*
184245
* @return A P2 that calls this P2 once for any given element and remembers the value for subsequent calls.

core/src/main/java/fj/P3.java

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,58 @@ public final P1<C> _3_() {
122122
return F1Functions.lazy(P3.<A, B, C>__3()).f(this);
123123
}
124124

125+
126+
/**
127+
* Creates a {@link P4} by adding the given element to the current {@link P3}
128+
*
129+
* @param el the element to append
130+
* @return A {@link P4} containing the original {@link P3} with the extra element added at the end
131+
*/
132+
public final <D> P4<A, B, C, D> append(D el) {
133+
return P.p(_1(), _2(), _3(), el);
134+
}
135+
136+
/**
137+
* Creates a {@link P5} by adding the given element to the current {@link P3}
138+
*
139+
* @param el the element to append
140+
* @return A {@link P5} containing the original {@link P3} with the extra element added at the end
141+
*/
142+
public final <D, E> P5<A, B, C, D, E> append(P2<D, E> el) {
143+
return P.p(_1(), _2(), _3(), el._1(), el._2());
144+
}
145+
146+
/**
147+
* Creates a {@link P6} by adding the given element to the current {@link P3}
148+
*
149+
* @param el the element to append
150+
* @return A {@link P6} containing the original {@link P3} with the extra element added at the end
151+
*/
152+
public final <D, E, F> P6<A, B, C, D, E, F> append(P3<D, E, F> el) {
153+
return P.p(_1(), _2(), _3(), el._1(), el._2(), el._3());
154+
}
155+
156+
/**
157+
* Creates a {@link P7} by adding the given element to the current {@link P3}
158+
*
159+
* @param el the element to append
160+
* @return A {@link P7} containing the original {@link P3} with the extra element added at the end
161+
*/
162+
public final <D, E, F, G> P7<A, B, C, D, E, F, G> append(P4<D, E, F, G> el) {
163+
return P.p(_1(), _2(), _3(), el._1(), el._2(), el._3(), el._4());
164+
}
165+
166+
/**
167+
* Creates a {@link P8} by adding the given element to the current {@link P3}
168+
*
169+
* @param el the element to append
170+
* @return A {@link P8} containing the original {@link P3} with the extra element added at the end
171+
*/
172+
public final <D, E, F, G, H> P8<A, B, C, D, E, F, G, H> append(P5<D, E, F, G, H> el) {
173+
return P.p(_1(), _2(), _3(), el._1(), el._2(), el._3(), el._4(), el._5());
174+
}
175+
176+
125177
/**
126178
* Provides a memoising P3 that remembers its values.
127179
*

core/src/main/java/fj/P4.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,50 @@ public final P1<D> _4_() {
176176
return F1Functions.lazy(P4.<A, B, C, D>__4()).f(this);
177177
}
178178

179+
180+
/**
181+
* Creates a {@link P5} by adding the given element to the current {@link P4}
182+
*
183+
* @param el the element to append
184+
* @return A {@link P5} containing the original {@link P4} with the extra element added at the end
185+
*/
186+
public final <E> P5<A, B, C, D, E> append(E el) {
187+
return P.p(_1(), _2(), _3(), _4(), el);
188+
}
189+
190+
/**
191+
* Creates a {@link P6} by adding the given element to the current {@link P4}
192+
*
193+
* @param el the element to append
194+
* @return A {@link P6} containing the original {@link P4} with the extra element added at the end
195+
*/
196+
public final <E, F> P6<A, B, C, D, E, F> append(P2<E, F> el) {
197+
return P.p(_1(), _2(), _3(), _4(), el._1(), el._2());
198+
}
199+
200+
/**
201+
* Creates a {@link P7} by adding the given element to the current {@link P4}
202+
*
203+
* @param el the element to append
204+
* @return A {@link P7} containing the original {@link P4} with the extra element added at the end
205+
*/
206+
public final <E, F, G> P7<A, B, C, D, E, F, G> append(P3<E, F, G> el) {
207+
return P.p(_1(), _2(), _3(), _4(), el._1(), el._2(), el._3());
208+
}
209+
210+
/**
211+
* Creates a {@link P8} by adding the given element to the current {@link P4}
212+
*
213+
* @param el the element to append
214+
* @return A {@link P8} containing the original {@link P4} with the extra element added at the end
215+
*/
216+
public final <E, F, G, H> P8<A, B, C, D, E, F, G, H> append(P4<E, F, G, H> el) {
217+
return P.p(_1(), _2(), _3(), _4(), el._1(), el._2(), el._3(), el._4());
218+
}
219+
220+
221+
222+
179223
/**
180224
* Provides a memoising P4 that remembers its values.
181225
*

core/src/main/java/fj/P5.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,36 @@ public final P1<E> _5_() {
238238
return F1Functions.lazy(P5.<A, B, C, D, E>__5()).f(this);
239239
}
240240

241+
/**
242+
* Creates a {@link P6} by adding the given element to the current {@link P5}
243+
*
244+
* @param el the element to append
245+
* @return A {@link P6} containing the original {@link P5} with the extra element added at the end
246+
*/
247+
public final <F> P6<A, B, C, D, E, F> append(F el) {
248+
return P.p(_1(), _2(), _3(), _4(), _5(), el);
249+
}
250+
251+
/**
252+
* Creates a {@link P7} by adding the given element to the current {@link P5}
253+
*
254+
* @param el the element to append
255+
* @return A {@link P7} containing the original {@link P5} with the extra element added at the end
256+
*/
257+
public final <F, G> P7<A, B, C, D, E, F, G> append(P2<F, G> el) {
258+
return P.p(_1(), _2(), _3(), _4(), _5(), el._1(), el._2());
259+
}
260+
261+
/**
262+
* Creates a {@link P8} by adding the given element to the current {@link P5}
263+
*
264+
* @param el the element to append
265+
* @return A {@link P8} containing the original {@link P5} with the extra element added at the end
266+
*/
267+
public final <F, G, H> P8<A, B, C, D, E, F, G, H> append(P3<F, G, H> el) {
268+
return P.p(_1(), _2(), _3(), _4(), _5(), el._1(), el._2(), el._3());
269+
}
270+
241271
/**
242272
* Provides a memoising P5 that remembers its values.
243273
*

core/src/main/java/fj/P6.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,26 @@ public final P1<F> _6_() {
309309
return F1Functions.lazy(P6.<A, B, C, D, E, F>__6()).f(this);
310310
}
311311

312+
/**
313+
* Creates a {@link P7} by adding the given element to the current {@link P6}
314+
*
315+
* @param el the element to append
316+
* @return A {@link P7} containing the original {@link P6} with the extra element added at the end
317+
*/
318+
public final <G> P7<A, B, C, D, E, F, G> append(G el) {
319+
return P.p(_1(), _2(), _3(), _4(), _5(), _6(), el);
320+
}
321+
322+
/**
323+
* Creates a {@link P8} by adding the given element to the current {@link P6}
324+
*
325+
* @param el the element to append
326+
* @return A {@link P8} containing the original {@link P6} with the extra element added at the end
327+
*/
328+
public final <G, H> P8<A, B, C, D, E, F, G, H> append(P2<G, H> el) {
329+
return P.p(_1(), _2(), _3(), _4(), _5(), _6(), el._1(), el._2());
330+
}
331+
312332
/**
313333
* Provides a memoising P6 that remembers its values.
314334
*

core/src/main/java/fj/P7.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,16 @@ public final P1<G> _7_() {
387387
return F1Functions.lazy(P7.<A, B, C, D, E, F, G>__7()).f(this);
388388
}
389389

390+
/**
391+
* Creates a {@link P8} by adding the given element to the current {@link P7}
392+
*
393+
* @param el the element to append
394+
* @return A {@link P8} containing the original {@link P7} with the extra element added at the end
395+
*/
396+
public final <H> P8<A, B, C, D, E, F, G, H> append(H el) {
397+
return P.p(_1(), _2(), _3(), _4(), _5(), _6(), _7(), el);
398+
}
399+
390400
/**
391401
* Provides a memoising P7 that remembers its values.
392402
*

0 commit comments

Comments
 (0)