是否有可能将任意多个定时磁通量合并为一个?

问题描述 投票:2回答:1

我知道combineLatest()将两到六个Flux实例中的最后一个值组合起来(Combining Publishers in Project )。但是,假设我有一个List<Flux<Integer>> listOfFlux。是否有可能将它们全部组合成一个,例如, listOfFlux.combineAllLatest( (a,b) -> a + b) )

reactive-programming project-reactor
1个回答
2
投票

是的,只有一个运营商变体:

Flux.combineLatest(Iterable<? extends Publisher<? extends T>> sources,
                                          Function<Object[],V> combinator)

您可以像以下一样使用它:

List<Flux<Integer>> listOfFlux = //...
Flux<Integer> result = Flux.combineLatest(listOfFlux, arr -> {
    //...
});
© www.soinside.com 2019 - 2024. All rights reserved.