I have a list of String.
For example:
List<String> ids = new ArrayList<>(List.of("q1", "q2", "q3"));
I want to filter this list using a function that returns Mono<Boolean>
. How do I do that?
function:
public Mono<Boolean> checkIfIdExists(String id)
{
//External call
}
It's probably easiest to create a Flux
from your List
then use filterWhen()
on that:
Flux.fromIterable(ids).filterWhen(id -> !checkIfIdExists(id)).collectList()
(Note this will of course give you a Mono<List<String>>
rather than a List<String>
, as since your filter is reactive, the final result will be reative also. If you're not working reactively but just using a reactive library, you can just call block()
to get the actual result.)
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