File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed
java8/src/main/java/fj/data Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change 1+ package fj .data ;
2+
3+ import java .util .stream .Collector ;
4+
5+ public final class Collectors {
6+
7+ private Collectors () {
8+ }
9+
10+ public static <A > Collector <A , List .Buffer <A >, List <A >> toList () {
11+ return Collector .of (
12+ List .Buffer ::new ,
13+ List .Buffer ::snoc ,
14+ (acc1 , acc2 ) -> acc1 .append (acc2 .toList ()),
15+ List .Buffer ::toList
16+ );
17+ }
18+
19+ public static <A > Collector <A , List .Buffer <A >, Array <A >> toArray () {
20+ return Collector .of (
21+ List .Buffer ::new ,
22+ List .Buffer ::snoc ,
23+ (acc1 , acc2 ) -> acc1 .append (acc2 .toList ()),
24+ (buf ) -> Array .iterableArray (buf .toList ())
25+ );
26+ }
27+
28+ public static <A > Collector <A , List .Buffer <A >, Stream <A >> toStream () {
29+ return Collector .of (
30+ List .Buffer ::new ,
31+ List .Buffer ::snoc ,
32+ (acc1 , acc2 ) -> acc1 .append (acc2 .toList ()),
33+ (buf ) -> Stream .iterableStream (buf .toList ())
34+ );
35+ }
36+ }
You can’t perform that action at this time.
0 commit comments