How to transform reactive chain to either true or false depending if empty

Viewed 30
Mono<SingleChoice> filter = Mono.just(this)
.filter(predicate)
.//return true if data still exists else false
;

I would like to write a logic where i validate mono by filter operator. So if filter pass then mono contains data but if filter failed then there is an empty mono, but i don't need the object on which filter was performed instead i need boolean result. how could i achieve this is reactive programing.

1 Answers

The hasElement operator does exactly what you describe. You can use it like this:

Mono<Boolean> booleanMono = Mono.just(11)
    .filter(i -> i > 10)
    .hasElement();
Related