Joh*_*han 6 kotlin project-reactor spring-webflux arrow-kt
我正在使用Kotlin和Arrow以及. 我想做的是将Mono实例转换为Either。spring-webflux
当响应成功或返回错误时Either调用创建实例。Either.right(..)WebClientEither.left(..)WebClient
我正在寻找一种Mono类似于Either.fold(..)的方法,我可以在其中映射成功和错误的结果,并返回与Mono. 像这样的东西(伪代码不起作用):
val either : Either<Throwable, ClientResponse> =
webClient().post().exchange()
.fold({ throwable -> Either.left(throwable) },
{ response -> Either.right(response)})
Run Code Online (Sandbox Code Playgroud)
一个人应该怎样走呢?
没有fold方法,Mono但您可以使用两种方法实现相同的目的:map和onErrorResume。事情会是这样的:
val either : Either<Throwable, ClientResponse> =
webClient().post()
.exchange()
.map { Either.right(it) }
.onErrorResume { Either.left(it).toMono() }
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3069 次 |
| 最近记录: |