I am trying to figure out how to use this signature of .zip
public static <R> Mono<R> zip(final Iterable<? extends Mono<?>> monos, Function<? super Object[], ? extends R> combinator) {
return onAssembly(new MonoZip<>(false, combinator, monos));
}
I have multiple monos create from webclient request that I would like zip up. Supplying each mono separately like so works:
Mono.zip(m1, m2, m3, (a, b, c) -> { })
But if a List of monos like
List<Mono> monos = new ArrayList();
Mono.zip(monos, () -> {});
I get an error: List<Mono> is not compatible with Iterable<? extends Mono<?>>
Is it proper to attempt to use .zip is this manner and if so, how can I accomplish this.
I can see there are two things here:
Iterable<? extends Mono<?>> monos meaning your first param (monos) has to be of generic type Mono<?>, for example Mono.public static <R> Mono<R> zip(final Iterable<? extends Mono<?>> monos, Function<? super Object[], ? extends R> combinator) {
return onAssembly(new MonoZip<>(false, combinator, monos));
}
A proper use of above method will be something like below:
List<Mono<YourObject>> monos = new ArrayList<>();
Mono.zip(monos, objectArray ->
Arrays.stream(objectArray)
.map(object -> yourMapperFunction(object))
.collect(Collectors.toList())
);
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