【发布时间】:2019-04-15 10:20:29
【问题描述】:
我有一个 Mono,我想将它与另一个 Mono 合并,如:
val firstMono = Mono.just("thing");
val secondMono = Mono.just("other thing");
val thirdMono = firstMono.zipWith(secondMono, function);
但我希望function 也返回一个Mono,没有以Mono<Mono<?>> 结尾
我能想到的最好的是:
val thirdMono = firstMono.zipWith(secondMono, function)
.flatMap(identity());
但这似乎有点不合时宜。
我也想过
val thirdMono = firstMono.zipWith(secondMono)
.flatMap(function);
但在这种情况下,我必须让 function 接受 Tuple2 而不是单独的参数,这更难看。
有什么想法吗?
【问题讨论】:
-
val thirdMono = firstMono.zipWith(secondMono).flatMap(pair -> function(pair.getT1(), pair.getT2()));... -
是的,我也有这个 - 工作,但使
Mono链丑陋......可能,我正在寻找不存在的东西 - 一些识别我的操作员我与另一个Mono一起工作。.flatZipWith会很好... -
我会选择
var thirdMono = firstMono.flatMap(left -> secondMono.flatMap(right -> function(left, right)));,但我想这是否“更漂亮”还有待商榷。
标签: java spring-webflux project-reactor