Mono flatMap + switchIfEmpty组合运算符?

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

是否有一个运算符可以处理结果/成功,无论Mono是否为空。例如:

Mono<Bar> result = sourceMono.flatMap(n -> process(n)).switchIfEmpty(process(null));

其中:

Mono<Bar> process(Foo in){
Optional<Foo> foo = Optional.ofNullable(in);
...
}

是否有一个允许以下或类似内容的快捷键运算符?

Mono<Bar> result = sourceMono.shortCut(process);

[更具体地说,mono.someOperator()返回Optional<Foo>,当Mono为空时将包含null,否则具有值。

我想避免创建如上所述的处理方法,而只是编写一个代码块,但不确定哪个操作员可以在不复制代码块的情况下提供帮助。

spring-webflux project-reactor spring-reactive spring-reactor
1个回答
1
投票

没有内置的运算符可以精确地执行您想要的操作。

© www.soinside.com 2019 - 2024. All rights reserved.