Does Mono/Flux have operators like Peek / IfPresent from the Stream / Optional API?

Viewed 4949

As title says, was wondering if, when working with Mono/Flux, are there any equivalent (or similar) operators to peek and ifPresent from the Java Stream API.

1 Answers

Flux#hasElement:

Emit a single boolean true if any of the elements of this Flux sequence is equal to the provided value. The implementation uses short-circuit logic and completes with true if an element matches the value.

Mono<Boolean> ifPresent = Flux.<Ob>just(...)
        .hasElement(value); // similar to ifPresent

Flux#doOnNext:

Add behavior (side-effect) triggered when the Flux emits an item.

Flux<Ob> flux = Flux.<Ob>just()
        .doOnNext(i -> {}); // similar to peek
Related