Conditional tests

Until now, we been discussed operators that work on original data. The Reactor framework provides Boolean operators that enable the testing of each of the data elements in the stream. There are two types of operators, as follows:

  • all: This operator takes a predicate and confirms whether all of the elements meet the specified criteria. This is the logical AND operator for all data elements.
  • any: This operator takes a predicate and confirms whether any single element meets the specified criteria. This is a logical OR for all data elements.

The results of the preceding methods are consolidated into a single Boolean result, as follows:

fibonacciGenerator.take(10).all(x -> x > 0).subscribe(t -> {
    System.out.println(t);
}); ...

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.