Sink.collect

Collect all input elements using a Java Collector.

Sink operators

Signature

Sink.collectSink.collect

Description

A Sink which materializes into a CompletionStage which will be completed with a result of the Java Collector transformation and reduction operations.

Example

Given a stream of numbers we can collect the numbers into a collection with the seq operator

Java
sourcefinal List<Integer> list = Arrays.asList(1, 2, 3);
CompletionStage<List<Integer>> result =
    Source.from(list).runWith(Sink.collect(Collectors.toList()), system);

Reactive Streams semantics

cancels when the Collector throws an exception

backpressures when the Collector’s previous accumulation is still in progress