forked from functionaljava/functionaljava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunction.java
More file actions
866 lines (788 loc) · 29.1 KB
/
Function.java
File metadata and controls
866 lines (788 loc) · 29.1 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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
package fj;
import fj.data.Option;
/**
* Transformations on functions.
*
* @version %build.number%
*/
public final class Function {
private Function() {
throw new UnsupportedOperationException();
}
/**
* Function application with the arguments flipped.
*
* @param a The value to apply the function to.
* @return A function that is partially-applied to the given value.
*/
public static <A, B> F<F<A, B>, B> apply(final A a) {
return f -> f.f(a);
}
/**
* Function composition.
*
* @return A function that composes two functions to produce a new function.
*/
public static <A, B, C> F<F<B, C>, F<F<A, B>, F<A, C>>> compose() {
return f -> g -> compose(f, g);
}
/**
* Function composition.
*
* @param f A function to compose with another.
* @param g A function to compose with another.
* @return A function that is the composition of the given arguments.
*/
public static <A, B, C> F<A, C> compose(final F<B, C> f, final F<A, B> g) {
return a -> f.f(g.f(a));
}
/**
* Function composition.
*
* @param f A function to compose with another.
* @param g A function to compose with another.
* @return A function that is the composition of the given arguments.
*/
public static <A, B, C, D> F<A, F<B, D>> compose2(final F<C, D> f, final F<A, F<B, C>> g) {
return a -> b -> f.f(g.f(a).f(b));
}
/**
* Function composition flipped.
*
* @return A function that composes two functions to produce a new function.
*/
public static <A, B, C> F<F<A, B>, F<F<B, C>, F<A, C>>> andThen() {
return g -> f -> andThen(g, f);
}
/**
* Function composition flipped.
*
* @param g A function to compose with another.
* @param f A function to compose with another.
* @return A function that is the composition of the given arguments.
*/
public static <A, B, C> F<A, C> andThen(final F<A, B> g, final F<B, C> f) {
return a -> f.f(g.f(a));
}
/**
* The identity transformation.
*
* @return The identity transformation.
*/
public static <A> F<A, A> identity() {
return a -> a;
}
/**
* Returns a function that given an argument, returns a function that ignores its argument.
*
* @return A function that given an argument, returns a function that ignores its argument.
*/
public static <A, B> F<B, F<A, B>> constant() {
return Function::constant;
}
/**
* Returns a function that ignores its argument to constantly produce the given value.
*
* @param b The value to return when the returned function is applied.
* @return A function that ignores its argument to constantly produce the given value.
*/
public static <A, B> F<A, B> constant(final B b) {
return a -> b;
}
/**
* Simultaneously covaries and contravaries a function.
*
* @param f The function to vary.
* @return A co- and contravariant function that invokes f on its argument.
*/
public static <A, B> F<A, B> vary(final F<? super A, ? extends B> f) {
return f::f;
}
/**
* Simultaneously covaries and contravaries a function.
*
* @return A function that varies and covaries a function.
*/
public static <C, A extends C, B, D extends B> F<F<C, D>, F<A, B>> vary() {
return Function::<A, B>vary;
}
/**
* Function argument flipping.
*
* @return A function that takes a function and flips its arguments.
*/
public static <A, B, C> F<F<A, F<B, C>>, F<B, F<A, C>>> flip() {
return Function::flip;
}
/**
* Function argument flipping.
*
* @param f The function to flip.
* @return The given function flipped.
*/
public static <A, B, C> F<B, F<A, C>> flip(final F<A, F<B, C>> f) {
return b -> a -> f.f(a).f(b);
}
/**
* Function argument flipping.
*
* @param f The function to flip.
* @return The given function flipped.
*/
public static <A, B, C> F2<B, A, C> flip(final F2<A, B, C> f) {
return (b, a) -> f.f(a, b);
}
/**
* Function argument flipping.
*
* @return A function that flips the arguments of a given function.
*/
public static <A, B, C> F<F2<A, B, C>, F2<B, A, C>> flip2() {
return Function::flip;
}
/**
* Return a function that inspects the argument of the given function for a <code>null</code> value and if so, does
* not apply the value, instead returning an empty optional value.
*
* @param f The function to check for a <code>null</code> argument.
* @return A function that inspects the argument of the given function for a <code>null</code> value and if so, does
* not apply the value, instead returning an empty optional value.
*/
public static <A, B> F<A, Option<B>> nullable(final F<A, B> f) {
return a -> a == null ? Option.none() : Option.some(f.f(a));
}
/**
* Curry a function of arity-2.
*
* @param f The function to curry.
* @return A curried form of the given function.
*/
public static <A, B, C> F<A, F<B, C>> curry(final F2<A, B, C> f) {
return a -> b -> f.f(a, b);
}
/**
* Curry a function of arity-2.
*
* @param f The function to curry.
* @param a An argument to the curried function.
* @return A curried form of the given function.
*/
public static <A, B, C> F<B, C> curry(final F2<A, B, C> f, final A a) {
return curry(f).f(a);
}
/**
* Uncurry a function of arity-2.
*
* @return An uncurried function.
*/
public static <A, B, C> F<F<A, F<B, C>>, F2<A, B, C>> uncurryF2() {
return Function::uncurryF2;
}
/**
* Uncurry a function of arity-2.
*
* @param f The function to uncurry.
* @return An uncurried function.
*/
public static <A, B, C> F2<A, B, C> uncurryF2(final F<A, F<B, C>> f) {
return (a, b) -> f.f(a).f(b);
}
/**
* Curry a function of arity-3.
*
* @param f The function to curry.
* @return A curried form of the given function.
*/
public static <A, B, C, D> F<A, F<B, F<C, D>>> curry(final F3<A, B, C, D> f) {
return a -> b -> c -> f.f(a, b, c);
}
/**
* Curry a function of arity-3.
*
* @param f The function to curry.
* @param a An argument to the curried function.
* @return A curried form of the given function.
*/
public static <A, B, C, D> F<B, F<C, D>> curry(final F3<A, B, C, D> f, final A a) {
return curry(f).f(a);
}
/**
* Curry a function of arity-3.
*
* @param f The function to curry.
* @param a An argument to the curried function.
* @param b An argument to the curried function.
* @return A curried form of the given function.
*/
public static <A, B, C, D> F<C, D> curry(final F3<A, B, C, D> f, final A a, final B b) {
return curry(f, a).f(b);
}
/**
* Uncurry a function of arity-3.
*
* @return An uncurried function.
*/
public static <A, B, C, D> F<F<A, F<B, F<C, D>>>, F3<A, B, C, D>> uncurryF3() {
return Function::uncurryF3;
}
/**
* Uncurry a function of arity-3.
*
* @param f The function to uncurry.
* @return An uncurried function.
*/
public static <A, B, C, D> F3<A, B, C, D> uncurryF3(final F<A, F<B, F<C, D>>> f) {
return (a, b, c) -> f.f(a).f(b).f(c);
}
/**
* Curry a function of arity-4.
*
* @param f The function to curry.
* @return A curried form of the given function.
*/
public static <A, B, C, D, E> F<A, F<B, F<C, F<D, E>>>> curry(final F4<A, B, C, D, E> f) {
return a -> b -> c -> d -> f.f(a, b, c, d);
}
/**
* Curry a function of arity-4.
*
* @param f The function to curry.
* @param a An argument to the curried function.
* @return A curried form of the given function.
*/
public static <A, B, C, D, E> F<B, F<C, F<D, E>>> curry(final F4<A, B, C, D, E> f, final A a) {
return curry(f).f(a);
}
/**
* Curry a function of arity-4.
*
* @param f The function to curry.
* @param a An argument to the curried function.
* @param b An argument to the curried function.
* @return A curried form of the given function.
*/
public static <A, B, C, D, E> F<C, F<D, E>> curry(final F4<A, B, C, D, E> f, final A a, final B b) {
return curry(f).f(a).f(b);
}
/**
* Curry a function of arity-4.
*
* @param f The function to curry.
* @param a An argument to the curried function.
* @param b An argument to the curried function.
* @param c An argument to the curried function.
* @return A curried form of the given function.
*/
public static <A, B, C, D, E> F<D, E> curry(final F4<A, B, C, D, E> f, final A a, final B b, final C c) {
return curry(f).f(a).f(b).f(c);
}
/**
* Uncurry a function of arity-4.
*
* @return An uncurried function.
*/
public static <A, B, C, D, E> F<F<A, F<B, F<C, F<D, E>>>>, F4<A, B, C, D, E>> uncurryF4() {
return Function::uncurryF4;
}
/**
* Uncurry a function of arity-4.
*
* @param f The function to uncurry.
* @return An uncurried function.
*/
public static <A, B, C, D, E> F4<A, B, C, D, E> uncurryF4(final F<A, F<B, F<C, F<D, E>>>> f) {
return (a, b, c, d) -> f.f(a).f(b).f(c).f(d);
}
/**
* Curry a function of arity-5.
*
* @param f The function to curry.
* @return A curried form of the given function.
*/
public static <A, B, C, D, E, F$> F<A, F<B, F<C, F<D, F<E, F$>>>>> curry(final F5<A, B, C, D, E, F$> f) {
return a -> b -> c -> d -> e -> f.f(a, b, c, d, e);
}
/**
* Curry a function of arity-5.
*
* @param f The function to curry.
* @param a An argument to the curried function.
* @return A curried form of the given function.
*/
public static <A, B, C, D, E, F$> F<B, F<C, F<D, F<E, F$>>>> curry(final F5<A, B, C, D, E, F$> f, final A a) {
return curry(f).f(a);
}
/**
* Curry a function of arity-5.
*
* @param f The function to curry.
* @param a An argument to the curried function.
* @param b An argument to the curried function.
* @return A curried form of the given function.
*/
public static <A, B, C, D, E, F$> F<C, F<D, F<E, F$>>> curry(final F5<A, B, C, D, E, F$> f, final A a, final B b) {
return curry(f).f(a).f(b);
}
/**
* Curry a function of arity-5.
*
* @param f The function to curry.
* @param a An argument to the curried function.
* @param b An argument to the curried function.
* @param c An argument to the curried function.
* @return A curried form of the given function.
*/
public static <A, B, C, D, E, F$> F<D, F<E, F$>> curry(final F5<A, B, C, D, E, F$> f, final A a, final B b,
final C c) {
return curry(f).f(a).f(b).f(c);
}
/**
* Curry a function of arity-5.
*
* @param f The function to curry.
* @param a An argument to the curried function.
* @param b An argument to the curried function.
* @param c An argument to the curried function.
* @param d An argument to the curried function.
* @return A curried form of the given function.
*/
public static <A, B, C, D, E, F$> F<E, F$> curry(final F5<A, B, C, D, E, F$> f, final A a, final B b, final C c,
final D d) {
return curry(f).f(a).f(b).f(c).f(d);
}
/**
* Uncurry a function of arity-5.
*
* @return An uncurried function.
*/
public static <A, B, C, D, E, F$> F<F<A, F<B, F<C, F<D, F<E, F$>>>>>, F5<A, B, C, D, E, F$>> uncurryF5() {
return Function::uncurryF5;
}
/**
* Uncurry a function of arity-6.
*
* @param f The function to uncurry.
* @return An uncurried function.
*/
public static <A, B, C, D, E, F$> F5<A, B, C, D, E, F$> uncurryF5(final F<A, F<B, F<C, F<D, F<E, F$>>>>> f) {
return (a, b, c, d, e) -> f.f(a).f(b).f(c).f(d).f(e);
}
/**
* Curry a function of arity-6.
*
* @param f The function to curry.
* @return A curried form of the given function.
*/
public static <A, B, C, D, E, F$, G> F<A, F<B, F<C, F<D, F<E, F<F$, G>>>>>> curry(final F6<A, B, C, D, E, F$, G> f) {
return a -> b -> c -> d -> e -> f$ -> f.f(a, b, c, d, e, f$);
}
/**
* Uncurry a function of arity-6.
*
* @return An uncurried function.
*/
public static <A, B, C, D, E, F$, G> F<F<A, F<B, F<C, F<D, F<E, F<F$, G>>>>>>, F6<A, B, C, D, E, F$, G>> uncurryF6() {
return Function::uncurryF6;
}
/**
* Uncurry a function of arity-6.
*
* @param f The function to uncurry.
* @return An uncurried function.
*/
public static <A, B, C, D, E, F$, G> F6<A, B, C, D, E, F$, G> uncurryF6(
final F<A, F<B, F<C, F<D, F<E, F<F$, G>>>>>> f) {
return (a, b, c, d, e, f$) -> f.f(a).f(b).f(c).f(d).f(e).f(f$);
}
/**
* Curry a function of arity-7.
*
* @param f The function to curry.
* @return A curried form of the given function.
*/
public static <A, B, C, D, E, F$, G, H> F<A, F<B, F<C, F<D, F<E, F<F$, F<G, H>>>>>>> curry(
final F7<A, B, C, D, E, F$, G, H> f) {
return a -> b -> c -> d -> e -> f$ -> g -> f.f(a, b, c, d, e, f$, g);
}
/**
* Curry a function of arity-7.
*
* @param f The function to curry.
* @param a An argument to the curried function.
* @return A curried form of the given function.
*/
public static <A, B, C, D, E, F$, G, H> F<B, F<C, F<D, F<E, F<F$, F<G, H>>>>>> curry(
final F7<A, B, C, D, E, F$, G, H> f, final A a) {
return curry(f).f(a);
}
/**
* Curry a function of arity-7.
*
* @param f The function to curry.
* @param a An argument to the curried function.
* @param b An argument to the curried function.
* @return A curried form of the given function.
*/
public static <A, B, C, D, E, F$, G, H> F<C, F<D, F<E, F<F$, F<G, H>>>>> curry(final F7<A, B, C, D, E, F$, G, H> f,
final A a, final B b) {
return curry(f).f(a).f(b);
}
/**
* Curry a function of arity-7.
*
* @param f The function to curry.
* @param a An argument to the curried function.
* @param b An argument to the curried function.
* @param c An argument to the curried function.
* @return A curried form of the given function.
*/
public static <A, B, C, D, E, F$, G, H> F<D, F<E, F<F$, F<G, H>>>> curry(final F7<A, B, C, D, E, F$, G, H> f,
final A a, final B b, final C c) {
return curry(f).f(a).f(b).f(c);
}
/**
* Curry a function of arity-7.
*
* @param f The function to curry.
* @param a An argument to the curried function.
* @param b An argument to the curried function.
* @param c An argument to the curried function.
* @param d An argument to the curried function.
* @return A curried form of the given function.
*/
public static <A, B, C, D, E, F$, G, H> F<E, F<F$, F<G, H>>> curry(final F7<A, B, C, D, E, F$, G, H> f, final A a,
final B b, final C c, final D d) {
return curry(f).f(a).f(b).f(c).f(d);
}
/**
* Curry a function of arity-7.
*
* @param f The function to curry.
* @param a An argument to the curried function.
* @param b An argument to the curried function.
* @param c An argument to the curried function.
* @param d An argument to the curried function.
* @param e An argument to the curried function.
* @return A curried form of the given function.
*/
public static <A, B, C, D, E, F$, G, H> F<F$, F<G, H>> curry(final F7<A, B, C, D, E, F$, G, H> f, final A a,
final B b, final C c, final D d, final E e) {
return curry(f).f(a).f(b).f(c).f(d).f(e);
}
/**
* Curry a function of arity-7.
*
* @param f The function to curry.
* @param a An argument to the curried function.
* @param b An argument to the curried function.
* @param c An argument to the curried function.
* @param d An argument to the curried function.
* @param e An argument to the curried function.
* @param f$ An argument to the curried function.
* @return A curried form of the given function.
*/
public static <A, B, C, D, E, F$, G, H> F<G, H> curry(final F7<A, B, C, D, E, F$, G, H> f, final A a, final B b,
final C c, final D d, final E e, final F$ f$) {
return curry(f).f(a).f(b).f(c).f(d).f(e).f(f$);
}
/**
* Uncurry a function of arity-7.
*
* @return An uncurried function.
*/
public static <A, B, C, D, E, F$, G, H> F<F<A, F<B, F<C, F<D, F<E, F<F$, F<G, H>>>>>>>, F7<A, B, C, D, E, F$, G, H>> uncurryF7() {
return Function::uncurryF7;
}
/**
* Uncurry a function of arity-7.
*
* @param f The function to uncurry.
* @return An uncurried function.
*/
public static <A, B, C, D, E, F$, G, H> F7<A, B, C, D, E, F$, G, H> uncurryF7(
final F<A, F<B, F<C, F<D, F<E, F<F$, F<G, H>>>>>>> f) {
return (a, b, c, d, e, f$, g) -> f.f(a).f(b).f(c).f(d).f(e).f(f$).f(g);
}
/**
* Curry a function of arity-8.
*
* @param f The function to curry.
* @return A curried form of the given function.
*/
public static <A, B, C, D, E, F$, G, H, I> F<A, F<B, F<C, F<D, F<E, F<F$, F<G, F<H, I>>>>>>>> curry(
final F8<A, B, C, D, E, F$, G, H, I> f) {
return a -> b -> c -> d -> e -> f$ -> g -> h -> f.f(a, b, c, d, e, f$, g, h);
}
/**
* Curry a function of arity-8.
*
* @param f The function to curry.
* @param a An argument to the curried function.
* @return A curried form of the given function.
*/
public static <A, B, C, D, E, F$, G, H, I> F<B, F<C, F<D, F<E, F<F$, F<G, F<H, I>>>>>>> curry(
final F8<A, B, C, D, E, F$, G, H, I> f, final A a) {
return curry(f).f(a);
}
/**
* Curry a function of arity-8.
*
* @param f The function to curry.
* @param a An argument to the curried function.
* @param b An argument to the curried function.
* @return A curried form of the given function.
*/
public static <A, B, C, D, E, F$, G, H, I> F<C, F<D, F<E, F<F$, F<G, F<H, I>>>>>> curry(
final F8<A, B, C, D, E, F$, G, H, I> f, final A a, final B b) {
return curry(f).f(a).f(b);
}
/**
* Curry a function of arity-8.
*
* @param f The function to curry.
* @param a An argument to the curried function.
* @param b An argument to the curried function.
* @param c An argument to the curried function.
* @return A curried form of the given function.
*/
public static <A, B, C, D, E, F$, G, H, I> F<D, F<E, F<F$, F<G, F<H, I>>>>> curry(
final F8<A, B, C, D, E, F$, G, H, I> f, final A a, final B b, final C c) {
return curry(f).f(a).f(b).f(c);
}
/**
* Curry a function of arity-8.
*
* @param f The function to curry.
* @param a An argument to the curried function.
* @param b An argument to the curried function.
* @param c An argument to the curried function.
* @param d An argument to the curried function.
* @return A curried form of the given function.
*/
public static <A, B, C, D, E, F$, G, H, I> F<E, F<F$, F<G, F<H, I>>>> curry(final F8<A, B, C, D, E, F$, G, H, I> f,
final A a, final B b, final C c,
final D d) {
return curry(f).f(a).f(b).f(c).f(d);
}
/**
* Curry a function of arity-8.
*
* @param f The function to curry.
* @param a An argument to the curried function.
* @param b An argument to the curried function.
* @param c An argument to the curried function.
* @param d An argument to the curried function.
* @param e An argument to the curried function.
* @return A curried form of the given function.
*/
public static <A, B, C, D, E, F$, G, H, I> F<F$, F<G, F<H, I>>> curry(final F8<A, B, C, D, E, F$, G, H, I> f,
final A a, final B b, final C c, final D d,
final E e) {
return curry(f).f(a).f(b).f(c).f(d).f(e);
}
/**
* Curry a function of arity-8.
*
* @param f The function to curry.
* @param a An argument to the curried function.
* @param b An argument to the curried function.
* @param c An argument to the curried function.
* @param d An argument to the curried function.
* @param e An argument to the curried function.
* @param f$ An argument to the curried function.
* @return A curried form of the given function.
*/
public static <A, B, C, D, E, F$, G, H, I> F<G, F<H, I>> curry(final F8<A, B, C, D, E, F$, G, H, I> f, final A a,
final B b, final C c, final D d, final E e,
final F$ f$) {
return curry(f).f(a).f(b).f(c).f(d).f(e).f(f$);
}
/**
* Curry a function of arity-7.
*
* @param f The function to curry.
* @param a An argument to the curried function.
* @param b An argument to the curried function.
* @param c An argument to the curried function.
* @param d An argument to the curried function.
* @param e An argument to the curried function.
* @param f$ An argument to the curried function.
* @param g An argument to the curried function.
* @return A curried form of the given function.
*/
public static <A, B, C, D, E, F$, G, H, I> F<H, I> curry(final F8<A, B, C, D, E, F$, G, H, I> f, final A a, final B b,
final C c, final D d, final E e, final F$ f$, final G g) {
return curry(f).f(a).f(b).f(c).f(d).f(e).f(f$).f(g);
}
/**
* Uncurry a function of arity-8.
*
* @return An uncurried function.
*/
public static <A, B, C, D, E, F$, G, H, I> F<F<A, F<B, F<C, F<D, F<E, F<F$, F<G, F<H, I>>>>>>>>, F8<A, B, C, D, E, F$, G, H, I>> uncurryF8() {
return Function::uncurryF8;
}
/**
* Uncurry a function of arity-8.
*
* @param f The function to uncurry.
* @return An uncurried function.
*/
public static <A, B, C, D, E, F$, G, H, I> F8<A, B, C, D, E, F$, G, H, I> uncurryF8(
final F<A, F<B, F<C, F<D, F<E, F<F$, F<G, F<H, I>>>>>>>> f) {
return (a, b, c, d, e, f$, g, h) -> f.f(a).f(b).f(c).f(d).f(e).f(f$).f(g).f(h);
}
/**
* Binds the function in the second argument to the function in the first argument.
*
* @param ma A function whose argument type is the same as the argument type of the return value.
* @param f A function whose argument type is the same as the return type of <em>ma</em>,
* and yields the return value.
* @return A function that chains the given functions together such that the result of applying
* <em>ma</em> to the argument is given to <i>f</i>, yielding a function
* that is applied to the argument again.
*/
public static <A, B, C> F<C, B> bind(final F<C, A> ma, final F<A, F<C, B>> f) {
return m -> f.f(ma.f(m)).f(m);
}
/**
* Performs function application within a higher-order function (applicative functor pattern).
*
* @param cab The higher-order function to apply a function to.
* @param ca A function to apply within a higher-order function.
* @return A new function after applying the given higher-order function to the given function.
*/
public static <A, B, C> F<C, B> apply(final F<C, F<A, B>> cab, final F<C, A> ca) {
return apply(uncurryF2(cab), ca);
}
/**
* Performs function application within a higher-order function (applicative functor pattern).
*
* @param cab The higher-order function to apply a function to.
* @param ca A function to apply within a higher-order function.
* @return A new function after applying the given higher-order function to the given function.
*/
public static <A, B, C> F<C, B> apply(final F2<C, A, B> cab, final F<C, A> ca) {
return c -> cab.f(c, ca.f(c));
}
/**
* Binds the given function <em>f</em> to the values of the given functions, with a final join.
*
* @param ca A function to bind <em>f</em> function to.
* @param cb A function to bind <em>f</em> function to.
* @param f The bound function to be composed with <em>ca</em> and then applied with <em>cb</em>
* @return A new function after performing the composition, then application.
*/
public static <A, B, C, D> F<D, C> bind(final F<D, A> ca, final F<D, B> cb, final F<A, F<B, C>> f) {
return apply(compose(f, ca), cb);
}
/**
* Applies a given function over the arguments of another function of arity-2.
*
* @param a The function whose arguments to apply another function over.
* @param f The function to apply over the arguments of another function.
* @return A function whose arguments are fed through function f, before being passed to function a.
*/
public static <A, B, C> F<B, F<B, C>> on(final F<A, F<A, C>> a, final F<B, A> f) {
return compose(compose(Function.<B, A, C>andThen().f(f), a), f);
}
/**
* Promotes a function of arity-2 to a higher-order function.
*
* @param f The function to promote.
* @return A function of arity-2 promoted to compose with two functions.
*/
public static <A, B, C, D> F<F<D, A>, F<F<D, B>, F<D, C>>> lift(final F<A, F<B, C>> f) {
return curry((ca, cb) -> bind(ca, cb, f));
}
/**
* Joins two arguments of a function of arity-2 into one argument, yielding a function of arity-1.
*
* @param f A function whose arguments to join.
* @return A function of arity-1 whose argument is substituted for both parameters of <em>f</em>.
*/
public static <A, B> F<B, A> join(final F<B, F<B, A>> f) {
return bind(f, Function.identity());
}
/**
* Partial application of the second argument to the supplied function to get a function of type
* <tt>A -> C</tt>. Same as <tt>flip(f).f(b)</tt>.
*
* @param f The function to partially apply.
* @param b The value to apply to the function.
* @return A new function based on <tt>f</tt> with its second argument applied.
*/
public static <A, B, C> F<A, C> partialApply2(final F<A, F<B, C>> f, final B b) {
return a -> uncurryF2(f).f(a, b);
}
/**
* Partial application of the third argument to the supplied function to get a function of type
* <tt>A -> B -> D</tt>.
*
* @param f The function to partially apply.
* @param c The value to apply to the function.
* @return A new function based on <tt>f</tt> with its third argument applied.
*/
public static <A, B, C, D> F<A, F<B, D>> partialApply3(final F<A, F<B, F<C, D>>> f, final C c) {
return a -> b -> uncurryF3(f).f(a, b, c);
}
/**
* Partial application of the fourth argument to the supplied function to get a function of type
* <tt>A -> B -> C -> E</tt>.
*
* @param f The function to partially apply.
* @param d The value to apply to the function.
* @return A new function based on <tt>f</tt> with its fourth argument applied.
*/
public static <A, B, C, D, E> F<A, F<B, F<C, E>>> partialApply4(final F<A, F<B, F<C, F<D, E>>>> f, final D d) {
return a -> b -> c -> uncurryF4(f).f(a, b, c, d);
}
/**
* Partial application of the fifth argument to the supplied function to get a function of type
* <tt>A -> B -> C -> D -> F$</tt>.
*
* @param f The function to partially apply.
* @param e The value to apply to the function.
* @return A new function based on <tt>f</tt> with its fifth argument applied.
*/
public static <A, B, C, D, E, F$> F<A, F<B, F<C, F<D, F$>>>> partialApply5(final F<A, F<B, F<C, F<D, F<E, F$>>>>> f,
final E e) {
return a -> b -> c -> d -> uncurryF5(f).f(a, b, c, d, e);
}
/**
* Partial application of the sixth argument to the supplied function to get a function of type
* <tt>A -> B -> C -> D -> E -> G</tt>.
*
* @param f The function to partially apply.
* @param f$ The value to apply to the function.
* @return A new function based on <tt>f</tt> with its sixth argument applied.
*/
public static <A, B, C, D, E, F$, G> F<A, F<B, F<C, F<D, F<E, G>>>>> partialApply6(
final F<A, F<B, F<C, F<D, F<E, F<F$, G>>>>>> f, final F$ f$) {
return a -> b -> c -> d -> e -> uncurryF6(f).f(a, b, c, d, e, f$);
}
/**
* Partial application of the seventh argument to the supplied function to get a function of type
* <tt>A -> B -> C -> D -> E -> F$ -> H</tt>.
*
* @param f The function to partially apply.
* @param g The value to apply to the function.
* @return A new function based on <tt>f</tt> with its seventh argument applied.
*/
public static <A, B, C, D, E, F$, G, H> F<A, F<B, F<C, F<D, F<E, F<F$, H>>>>>> partialApply7(
final F<A, F<B, F<C, F<D, F<E, F<F$, F<G, H>>>>>>> f, final G g) {
return a -> b -> c -> d -> e -> f$ -> uncurryF7(f).f(a, b, c, d, e, f$, g);
}
/**
* Partial application of the eigth argument to the supplied function to get a function of type
* <tt>A -> B -> C -> D -> E -> F$ -> G -> I</tt>.
*
* @param f The function to partially apply.
* @param h The value to apply to the function.
* @return A new function based on <tt>f</tt> with its eigth argument applied.
*/
public static <A, B, C, D, E, F$, G, H, I> F<A, F<B, F<C, F<D, F<E, F<F$, F<G, I>>>>>>> partialApply8(
final F<A, F<B, F<C, F<D, F<E, F<F$, F<G, F<H, I>>>>>>>> f, final H h) {
return a -> b -> c -> d -> e -> f$ -> g -> uncurryF8(f).f(a, b, c, d, e, f$, g, h);
}
}