I have function that return Mono<Boolean>
and I want to map it to Mono<Void>
(since this is something I return in my Controller method).
Is there any better way to return such Mono
instead of .flatMap { Mono.empty<Void>() }
?
I can't use .map{ null }
because mapping function cannot accept null
s.
Instead of take(1) , you could use next() . This will transform the Flux into a valued Mono by taking the first emitted item, or an empty Mono if the Flux is empty itself.
flatMap. flatMapMany. Java Streams. Accepts Function SE -> SE which takes a synchronous element and returns a single synchronous element. Returns a Java Stream.
Default value if mono is empty. If you want to provide a default value when the mono is completed without any data, then use defaultIfEmpty method. For example, the following code tries to fetch the customer data from the database by using the customer id .
yes, simply use booleanMono.then()
. it only propagates the terminal signals (onComplete
or onError
) as a Mono<Void>
, ditching the onNext
event.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With