forked from functionaljava/functionaljava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathF.java
More file actions
852 lines (779 loc) · 24.6 KB
/
F.java
File metadata and controls
852 lines (779 loc) · 24.6 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
package fj;
import fj.control.parallel.Actor;
import fj.control.parallel.Promise;
import fj.control.parallel.Strategy;
import fj.data.Array;
import fj.data.Either;
import fj.data.IterableW;
import fj.data.List;
import fj.data.NonEmptyList;
import fj.data.Option;
import fj.data.Set;
import fj.data.Stream;
import fj.data.Tree;
import fj.data.TreeZipper;
import fj.data.Validation;
import fj.data.Zipper;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.TreeSet;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.PriorityBlockingQueue;
import java.util.concurrent.SynchronousQueue;
import static fj.data.Option.some;
import static fj.data.Stream.iterableStream;
import static fj.data.Zipper.fromStream;
/**
* A transformation or function from <code>A</code> to <code>B</code>. This type can be represented
* using the Java 7 closure syntax.
*
* @version %build.number%
*/
public abstract class F<A, B> {
/**
* Transform <code>A</code> to <code>B</code>.
*
* @param a The <code>A</code> to transform.
* @return The result of the transformation.
*/
public abstract B f(A a);
/**
* Function composition
*
* @param g A function to compose with this one.
* @return The composed function such that this function is applied last.
*/
public final <C> F<C, B> o(final F<C, A> g) {
return new F<C, B>() {
public B f(final C c) {
return F.this.f(g.f(c));
}
};
}
/**
* First-class function composition
*
* @return A function that composes this function with another.
*/
public final <C> F<F<C, A>, F<C, B>> o() {
return new F<F<C, A>, F<C, B>>() {
public F<C, B> f(final F<C, A> g) {
return F.this.o(g);
}
};
}
/**
* Function composition flipped.
*
* @param g A function with which to compose this one.
* @return The composed function such that this function is applied first.
*/
@SuppressWarnings({"unchecked"})
public final <C> F<A, C> andThen(final F<B, C> g) {
return g.o(this);
}
/**
* First-class composition flipped.
*
* @return A function that invokes this function and then a given function on the result.
*/
public final <C> F<F<B, C>, F<A, C>> andThen() {
return new F<F<B, C>, F<A, C>>() {
public F<A, C> f(final F<B, C> g) {
return F.this.andThen(g);
}
};
}
/**
* Binds a given function across this function (Reader Monad).
*
* @param g A function that takes the return value of this function as an argument, yielding a new function.
* @return A function that invokes this function on its argument and then the given function on the result.
*/
public final <C> F<A, C> bind(final F<B, F<A, C>> g) {
return new F<A, C>() {
@SuppressWarnings({"unchecked"})
public C f(final A a) {
return g.f(F.this.f(a)).f(a);
}
};
}
/**
* First-class function binding.
*
* @return A function that binds another function across this function.
*/
public final <C> F<F<B, F<A, C>>, F<A, C>> bind() {
return new F<F<B, F<A, C>>, F<A, C>>() {
public F<A, C> f(final F<B, F<A, C>> g) {
return F.this.bind(g);
}
};
}
/**
* Function application in an environment (Applicative Functor).
*
* @param g A function with the same argument type as this function, yielding a function that takes the return
* value of this function.
* @return A new function that invokes the given function on its argument, yielding a new function that is then
* applied to the result of applying this function to the argument.
*/
public final <C> F<A, C> apply(final F<A, F<B, C>> g) {
return new F<A, C>() {
@SuppressWarnings({"unchecked"})
public C f(final A a) {
return g.f(a).f(F.this.f(a));
}
};
}
/**
* First-class function application in an environment.
*
* @return A function that applies a given function within the environment of this function.
*/
public final <C> F<F<A, F<B, C>>, F<A, C>> apply() {
return new F<F<A, F<B, C>>, F<A, C>>() {
public F<A, C> f(final F<A, F<B, C>> g) {
return F.this.apply(g);
}
};
}
/**
* Applies this function over the arguments of another function.
*
* @param g The function over whose arguments to apply this function.
* @return A new function that invokes this function on its arguments before invoking the given function.
*/
public final <C> F<A, F<A, C>> on(final F<B, F<B, C>> g) {
return new F<A, F<A, C>>() {
public F<A, C> f(final A a1) {
return new F<A, C>() {
@SuppressWarnings({"unchecked"})
public C f(final A a2) {
return g.f(F.this.f(a1)).f(F.this.f(a2));
}
};
}
};
}
/**
* Applies this function over the arguments of another function.
*
* @return A function that applies this function over the arguments of another function.
*/
public final <C> F<F<B, F<B, C>>, F<A, F<A, C>>> on() {
return new F<F<B, F<B, C>>, F<A, F<A, C>>>() {
public F<A, F<A, C>> f(final F<B, F<B, C>> g) {
return F.this.on(g);
}
};
}
/**
* Promotes this function so that it returns its result in a product-1. Kleisli arrow for P1.
*
* @return This function promoted to return its result in a product-1.
*/
public final F<A, P1<B>> lazy() {
return new F<A, P1<B>>() {
public P1<B> f(final A a) {
return new P1<B>() {
public B _1() {
return F.this.f(a);
}
};
}
};
}
/**
* Promotes this function to map over a product-1.
*
* @return This function promoted to map over a product-1.
*/
public final F<P1<A>, P1<B>> mapP1() {
return new F<P1<A>, P1<B>>() {
public P1<B> f(final P1<A> p) {
return p.map(F.this);
}
};
}
/**
* Promotes this function so that it returns its result in an Option. Kleisli arrow for Option.
*
* @return This function promoted to return its result in an Option.
*/
public final F<A, Option<B>> optionK() {
return new F<A, Option<B>>() {
public Option<B> f(final A a) {
return some(F.this.f(a));
}
};
}
/**
* Promotes this function to map over an optional value.
*
* @return This function promoted to map over an optional value.
*/
public final F<Option<A>, Option<B>> mapOption() {
return new F<Option<A>, Option<B>>() {
public Option<B> f(final Option<A> o) {
return o.map(F.this);
}
};
}
/**
* Promotes this function so that it returns its result in a List. Kleisli arrow for List.
*
* @return This function promoted to return its result in a List.
*/
public final F<A, List<B>> listK() {
return new F<A, List<B>>() {
public List<B> f(final A a) {
return List.single(F.this.f(a));
}
};
}
/**
* Promotes this function to map over a List.
*
* @return This function promoted to map over a List.
*/
public final F<List<A>, List<B>> mapList() {
return new F<List<A>, List<B>>() {
public List<B> f(final List<A> x) {
return x.map(F.this);
}
};
}
/**
* Promotes this function so that it returns its result in a Stream. Kleisli arrow for Stream.
*
* @return This function promoted to return its result in a Stream.
*/
public final F<A, Stream<B>> streamK() {
return new F<A, Stream<B>>() {
public Stream<B> f(final A a) {
return Stream.single(F.this.f(a));
}
};
}
/**
* Promotes this function to map over a Stream.
*
* @return This function promoted to map over a Stream.
*/
public final F<Stream<A>, Stream<B>> mapStream() {
return new F<Stream<A>, Stream<B>>() {
public Stream<B> f(final Stream<A> x) {
return x.map(F.this);
}
};
}
/**
* Promotes this function so that it returns its result in a Array. Kleisli arrow for Array.
*
* @return This function promoted to return its result in a Array.
*/
public final F<A, Array<B>> arrayK() {
return new F<A, Array<B>>() {
public Array<B> f(final A a) {
return Array.single(F.this.f(a));
}
};
}
/**
* Promotes this function to map over a Array.
*
* @return This function promoted to map over a Array.
*/
public final F<Array<A>, Array<B>> mapArray() {
return new F<Array<A>, Array<B>>() {
public Array<B> f(final Array<A> x) {
return x.map(F.this);
}
};
}
/**
* Returns a function that comaps over a given actor.
*
* @return A function that comaps over a given actor.
*/
public final F<Actor<B>, Actor<A>> comapActor() {
return new F<Actor<B>, Actor<A>>() {
public Actor<A> f(final Actor<B> a) {
return a.comap(F.this);
}
};
}
/**
* Promotes this function to a concurrent function that returns a Promise of a value.
*
* @param s A parallel strategy for concurrent execution.
* @return A concurrent function that returns a Promise of a value.
*/
public final F<A, Promise<B>> promiseK(final Strategy<Unit> s) {
return Promise.promise(s, this);
}
/**
* Promotes this function to map over a Promise.
*
* @return This function promoted to map over Promises.
*/
public final F<Promise<A>, Promise<B>> mapPromise() {
return new F<Promise<A>, Promise<B>>() {
public Promise<B> f(final Promise<A> p) {
return p.fmap(F.this);
}
};
}
/**
* Promotes this function so that it returns its result on the left side of an Either.
* Kleisli arrow for the Either left projection.
*
* @return This function promoted to return its result on the left side of an Either.
*/
@SuppressWarnings({"unchecked"})
public final <C> F<A, Either<B, C>> eitherLeftK() {
return Either.<B, C>left_().o(F.this);
}
/**
* Promotes this function so that it returns its result on the right side of an Either.
* Kleisli arrow for the Either right projection.
*
* @return This function promoted to return its result on the right side of an Either.
*/
@SuppressWarnings({"unchecked"})
public final <C> F<A, Either<C, B>> eitherRightK() {
return Either.<C, B>right_().o(F.this);
}
/**
* Promotes this function to map over the left side of an Either.
*
* @return This function promoted to map over the left side of an Either.
*/
@SuppressWarnings({"unchecked"})
public final <X> F<Either<A, X>, Either<B, X>> mapLeft() {
return Either.<A, X, B>leftMap_().f(F.this);
}
/**
* Promotes this function to map over the right side of an Either.
*
* @return This function promoted to map over the right side of an Either.
*/
@SuppressWarnings({"unchecked"})
public final <X> F<Either<X, A>, Either<X, B>> mapRight() {
return Either.<X, A, B>rightMap_().f(F.this);
}
/**
* Returns a function that returns the left side of a given Either, or this function applied to the right side.
*
* @return a function that returns the left side of a given Either, or this function applied to the right side.
*/
public final F<Either<B, A>, B> onLeft() {
return new F<Either<B, A>, B>() {
public B f(final Either<B, A> either) {
return either.left().on(F.this);
}
};
}
/**
* Returns a function that returns the right side of a given Either, or this function applied to the left side.
*
* @return a function that returns the right side of a given Either, or this function applied to the left side.
*/
public final F<Either<A, B>, B> onRight() {
return new F<Either<A, B>, B>() {
public B f(final Either<A, B> either) {
return either.right().on(F.this);
}
};
}
/**
* Promotes this function to return its value in an Iterable.
*
* @return This function promoted to return its value in an Iterable.
*/
@SuppressWarnings({"unchecked"})
public final F<A, IterableW<B>> iterableK() {
return IterableW.<A, B>arrow().f(F.this);
}
/**
* Promotes this function to map over Iterables.
*
* @return This function promoted to map over Iterables.
*/
@SuppressWarnings({"unchecked"})
public final F<Iterable<A>, IterableW<B>> mapIterable() {
return IterableW.<A, B>map().f(F.this).o(IterableW.<A, Iterable<A>>wrap());
}
/**
* Promotes this function to return its value in a NonEmptyList.
*
* @return This function promoted to return its value in a NonEmptyList.
*/
@SuppressWarnings({"unchecked"})
public final F<A, NonEmptyList<B>> nelK() {
return NonEmptyList.<B>nel().o(F.this);
}
/**
* Promotes this function to map over a NonEmptyList.
*
* @return This function promoted to map over a NonEmptyList.
*/
public final F<NonEmptyList<A>, NonEmptyList<B>> mapNel() {
return new F<NonEmptyList<A>, NonEmptyList<B>>() {
public NonEmptyList<B> f(final NonEmptyList<A> list) {
return list.map(F.this);
}
};
}
/**
* Promotes this function to return its value in a Set.
*
* @param o An order for the set.
* @return This function promoted to return its value in a Set.
*/
public final F<A, Set<B>> setK(final Ord<B> o) {
return new F<A, Set<B>>() {
public Set<B> f(final A a) {
return Set.single(o, F.this.f(a));
}
};
}
/**
* Promotes this function to map over a Set.
*
* @param o An order for the resulting set.
* @return This function promoted to map over a Set.
*/
public final F<Set<A>, Set<B>> mapSet(final Ord<B> o) {
return new F<Set<A>, Set<B>>() {
public Set<B> f(final Set<A> set) {
return set.map(o, F.this);
}
};
}
/**
* Promotes this function to return its value in a Tree.
*
* @return This function promoted to return its value in a Tree.
*/
public final F<A, Tree<B>> treeK() {
return new F<A, Tree<B>>() {
public Tree<B> f(final A a) {
return Tree.leaf(F.this.f(a));
}
};
}
/**
* Promotes this function to map over a Tree.
*
* @return This function promoted to map over a Tree.
*/
@SuppressWarnings({"unchecked"})
public final F<Tree<A>, Tree<B>> mapTree() {
return Tree.<A, B>fmap_().f(F.this);
}
/**
* Returns a function that maps this function over a tree and folds it with the given monoid.
*
* @param m The monoid with which to fold the mapped tree.
* @return a function that maps this function over a tree and folds it with the given monoid.
*/
public final F<Tree<A>, B> foldMapTree(final Monoid<B> m) {
return Tree.foldMap_(F.this, m);
}
/**
* Promotes this function to return its value in a TreeZipper.
*
* @return This function promoted to return its value in a TreeZipper.
*/
public final F<A, TreeZipper<B>> treeZipperK() {
return treeK().andThen(TreeZipper.<B>fromTree());
}
/**
* Promotes this function to map over a TreeZipper.
*
* @return This function promoted to map over a TreeZipper.
*/
public final F<TreeZipper<A>, TreeZipper<B>> mapTreeZipper() {
return new F<TreeZipper<A>, TreeZipper<B>>() {
public TreeZipper<B> f(final TreeZipper<A> zipper) {
return zipper.map(F.this);
}
};
}
/**
* Promotes this function so that it returns its result on the failure side of a Validation.
* Kleisli arrow for the Validation failure projection.
*
* @return This function promoted to return its result on the failure side of a Validation.
*/
public final <C> F<A, Validation<B, C>> failK() {
return new F<A, Validation<B, C>>() {
public Validation<B, C> f(final A a) {
return Validation.fail(F.this.f(a));
}
};
}
/**
* Promotes this function so that it returns its result on the success side of an Validation.
* Kleisli arrow for the Validation success projection.
*
* @return This function promoted to return its result on the success side of an Validation.
*/
public final <C> F<A, Validation<C, B>> successK() {
return new F<A, Validation<C, B>>() {
public Validation<C, B> f(final A a) {
return Validation.success(F.this.f(a));
}
};
}
/**
* Promotes this function to map over the failure side of a Validation.
*
* @return This function promoted to map over the failure side of a Validation.
*/
public final <X> F<Validation<A, X>, Validation<B, X>> mapFail() {
return new F<Validation<A, X>, Validation<B, X>>() {
public Validation<B, X> f(final Validation<A, X> validation) {
return validation.f().map(F.this);
}
};
}
/**
* Promotes this function to map over the success side of a Validation.
*
* @return This function promoted to map over the success side of a Validation.
*/
public final <X> F<Validation<X, A>, Validation<X, B>> mapSuccess() {
return new F<Validation<X, A>, Validation<X, B>>() {
public Validation<X, B> f(final Validation<X, A> validation) {
return validation.map(F.this);
}
};
}
/**
* Returns a function that returns the failure side of a given Validation,
* or this function applied to the success side.
*
* @return a function that returns the failure side of a given Validation,
* or this function applied to the success side.
*/
public final F<Validation<B, A>, B> onFail() {
return new F<Validation<B, A>, B>() {
public B f(final Validation<B, A> v) {
return v.f().on(F.this);
}
};
}
/**
* Returns a function that returns the success side of a given Validation,
* or this function applied to the failure side.
*
* @return a function that returns the success side of a given Validation,
* or this function applied to the failure side.
*/
public final F<Validation<A, B>, B> onSuccess() {
return new F<Validation<A, B>, B>() {
public B f(final Validation<A, B> v) {
return v.on(F.this);
}
};
}
/**
* Promotes this function to return its value in a Zipper.
*
* @return This function promoted to return its value in a Zipper.
*/
public final F<A, Zipper<B>> zipperK() {
return streamK().andThen(new F<Stream<B>, Zipper<B>>() {
public Zipper<B> f(final Stream<B> stream) {
return fromStream(stream).some();
}
});
}
/**
* Promotes this function to map over a Zipper.
*
* @return This function promoted to map over a Zipper.
*/
public final F<Zipper<A>, Zipper<B>> mapZipper() {
return new F<Zipper<A>, Zipper<B>>() {
public Zipper<B> f(final Zipper<A> zipper) {
return zipper.map(F.this);
}
};
}
/**
* Promotes this function to map over an Equal as a contravariant functor.
*
* @return This function promoted to map over an Equal as a contravariant functor.
*/
public final F<Equal<B>, Equal<A>> comapEqual() {
return new F<Equal<B>, Equal<A>>() {
public Equal<A> f(final Equal<B> equal) {
return equal.comap(F.this);
}
};
}
/**
* Promotes this function to map over a Hash as a contravariant functor.
*
* @return This function promoted to map over a Hash as a contravariant functor.
*/
public final F<Hash<B>, Hash<A>> comapHash() {
return new F<Hash<B>, Hash<A>>() {
public Hash<A> f(final Hash<B> hash) {
return hash.comap(F.this);
}
};
}
/**
* Promotes this function to map over a Show as a contravariant functor.
*
* @return This function promoted to map over a Show as a contravariant functor.
*/
public final F<Show<B>, Show<A>> comapShow() {
return new F<Show<B>, Show<A>>() {
public Show<A> f(final Show<B> s) {
return s.comap(F.this);
}
};
}
/**
* Promotes this function to map over the first element of a pair.
*
* @return This function promoted to map over the first element of a pair.
*/
public final <C> F<P2<A, C>, P2<B, C>> mapFst() {
return P2.map1_(F.this);
}
/**
* Promotes this function to map over the second element of a pair.
*
* @return This function promoted to map over the second element of a pair.
*/
public final <C> F<P2<C, A>, P2<C, B>> mapSnd() {
return P2.map2_(F.this);
}
/**
* Promotes this function to map over both elements of a pair.
*
* @return This function promoted to map over both elements of a pair.
*/
public final F<P2<A, A>, P2<B, B>> mapBoth() {
return new F<P2<A, A>, P2<B, B>>() {
public P2<B, B> f(final P2<A, A> aap2) {
return P2.map(F.this, aap2);
}
};
}
/**
* Maps this function over a SynchronousQueue.
*
* @param as A SynchronousQueue to map this function over.
* @return A new SynchronousQueue with this function applied to each element.
*/
public final SynchronousQueue<B> mapJ(final SynchronousQueue<A> as) {
final SynchronousQueue<B> bs = new SynchronousQueue<B>();
bs.addAll(iterableStream(as).map(this).toCollection());
return bs;
}
/**
* Maps this function over a PriorityBlockingQueue.
*
* @param as A PriorityBlockingQueue to map this function over.
* @return A new PriorityBlockingQueue with this function applied to each element.
*/
public final PriorityBlockingQueue<B> mapJ(final PriorityBlockingQueue<A> as) {
return new PriorityBlockingQueue<B>(iterableStream(as).map(this).toCollection());
}
/**
* Maps this function over a LinkedBlockingQueue.
*
* @param as A LinkedBlockingQueue to map this function over.
* @return A new LinkedBlockingQueue with this function applied to each element.
*/
public final LinkedBlockingQueue<B> mapJ(final LinkedBlockingQueue<A> as) {
return new LinkedBlockingQueue<B>(iterableStream(as).map(this).toCollection());
}
/**
* Maps this function over a CopyOnWriteArraySet.
*
* @param as A CopyOnWriteArraySet to map this function over.
* @return A new CopyOnWriteArraySet with this function applied to each element.
*/
public final CopyOnWriteArraySet<B> mapJ(final CopyOnWriteArraySet<A> as) {
return new CopyOnWriteArraySet<B>(iterableStream(as).map(this).toCollection());
}
/**
* Maps this function over a CopyOnWriteArrayList.
*
* @param as A CopyOnWriteArrayList to map this function over.
* @return A new CopyOnWriteArrayList with this function applied to each element.
*/
public final CopyOnWriteArrayList<B> mapJ(final CopyOnWriteArrayList<A> as) {
return new CopyOnWriteArrayList<B>(iterableStream(as).map(this).toCollection());
}
/**
* Maps this function over a ConcurrentLinkedQueue.
*
* @param as A ConcurrentLinkedQueue to map this function over.
* @return A new ConcurrentLinkedQueue with this function applied to each element.
*/
public final ConcurrentLinkedQueue<B> mapJ(final ConcurrentLinkedQueue<A> as) {
return new ConcurrentLinkedQueue<B>(iterableStream(as).map(this).toCollection());
}
/**
* Maps this function over an ArrayBlockingQueue.
*
* @param as An ArrayBlockingQueue to map this function over.
* @return A new ArrayBlockingQueue with this function applied to each element.
*/
public final ArrayBlockingQueue<B> mapJ(final ArrayBlockingQueue<A> as) {
final ArrayBlockingQueue<B> bs = new ArrayBlockingQueue<B>(as.size());
bs.addAll(iterableStream(as).map(this).toCollection());
return bs;
}
/**
* Maps this function over a TreeSet.
*
* @param as A TreeSet to map this function over.
* @return A new TreeSet with this function applied to each element.
*/
public final TreeSet<B> mapJ(final TreeSet<A> as) {
return new TreeSet<B>(iterableStream(as).map(this).toCollection());
}
/**
* Maps this function over a PriorityQueue.
*
* @param as A PriorityQueue to map this function over.
* @return A new PriorityQueue with this function applied to each element.
*/
public final PriorityQueue<B> mapJ(final PriorityQueue<A> as) {
return new PriorityQueue<B>(iterableStream(as).map(this).toCollection());
}
/**
* Maps this function over a LinkedList.
*
* @param as A LinkedList to map this function over.
* @return A new LinkedList with this function applied to each element.
*/
public final LinkedList<B> mapJ(final LinkedList<A> as) {
return new LinkedList<B>(iterableStream(as).map(this).toCollection());
}
/**
* Maps this function over an ArrayList.
*
* @param as An ArrayList to map this function over.
* @return A new ArrayList with this function applied to each element.
*/
public final ArrayList<B> mapJ(final ArrayList<A> as) {
return new ArrayList<B>(iterableStream(as).map(this).toCollection());
}
}