The concatWith operator

The concatWith operator makes it possible to append a value event after the published values. It takes a publisher as input and appends the published values after the first publisher has completed, as shown in the following diagram:

Let's suppose that we want to append some negative values at the end of our Fibonacci stream:

fibonacciGenerator.take(10) .concatWith(Flux.just( new Long[]{-1L,-2L,-3L,-4L})) .subscribe(t -> {    System.out.println(t);});

In the preceding code, we did the following things:

  • The take operator selected the first 10 elements for the stream.
  • The concatWith operator took a publisher. It appended ...

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.