The collect operator

Reactor also provides operators that make it possible to accumulate data streams as collections. The most basic of these is the collectList() operator. The operator accumulates the data as a list, as shown in the following diagram:

Let's take our Fibonacci example and collect the data into a list. The collector method provides a Mono publisher that will emit a single list containing all of the published data:

public void testFibonacciCollect() {
    Flux<Long> fibonacciGenerator = Flux.generate(
            () -> Tuples.<Long, Long>of(0L, 1L),
            (state, sink) -> {
                return Tuples.of(state.getT2(), state.getT1() ...

Get Hands-On Reactive Programming with Reactor now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.