I have my Flux flux1 and when I iterate over it, I also want to start this Flux again inside of it so I can access all of my items from flux1 while iterating over the items from flux1. Basically doing this but with Flux:
for(item in flux1){
for(item2 in flux1){
//xxxxx
}
}
Thank you
One possible solution would be to have a nested flatmap
, like this:
Flux<String> flux = Flux.just("a", "b", "c");
flux.flatMap(item -> flux.flatMap(item2 ->
doSomethingAsync(item, item2).doOnNext(e -> log.info("doSomethingAsync({}, {});", item, item2))))
Prints:
doSomethingAsync(a, a);
doSomethingAsync(a, b);
doSomethingAsync(a, c);
doSomethingAsync(b, a);
doSomethingAsync(b, b);
doSomethingAsync(b, c);
doSomethingAsync(c, a);
doSomethingAsync(c, b);
doSomethingAsync(c, c);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.