All Downloads are FREE. Search and download functionalities are using the official Maven repository.

fj.data.Collectors Maven / Gradle / Ivy

Go to download

Functional Java is an open source library that supports closures for the Java programming language

There is a newer version: 4.8.1
Show newest version
package fj.data;

import java.util.stream.Collector;

public final class Collectors {

  private Collectors() {
  }

  public static  Collector, List> toList() {
    return Collector.of(
        List.Buffer::new,
        List.Buffer::snoc,
        (acc1, acc2) -> acc1.append(acc2.toList()),
        List.Buffer::toList
    );
  }

  public static  Collector, Array> toArray() {
    return Collector.of(
        List.Buffer::new,
        List.Buffer::snoc,
        (acc1, acc2) -> acc1.append(acc2.toList()),
        (buf) -> buf.toList().toArray()
    );
  }

  public static  Collector, Stream> toStream() {
    return Collector.of(
        List.Buffer::new,
        List.Buffer::snoc,
        (acc1, acc2) -> acc1.append(acc2.toList()),
        (buf) -> buf.toList().toStream()
    );
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy