我知道 combineLatest()
将两到六个 Flux 实例中的最后一个值组合起来 ( Combining Publishers in Project )。但是,假设我有 List<Flux<Integer>> listOfFlux
。是否有可能以某种方式将它们全部合并为一个,例如listOfFlux.combineAllLatest( (a,b) -> a + b) )
?
最佳答案
是的,有一个专门用于此目的的运算符变体:
Flux.combineLatest(Iterable<? extends Publisher<? extends T>> sources,
Function<Object[],V> combinator)
您可以像这样使用它:
List<Flux<Integer>> listOfFlux = //...
Flux<Integer> result = Flux.combineLatest(listOfFlux, arr -> {
//...
});
关于reactive-programming - 是否可以将任意多个定时 Flux 合并为一个?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52182414/