【发布时间】:2018-04-24 11:23:46
【问题描述】:
我正在使用 Kotlin 和 Arrow 以及来自 spring-webflux 的 WebClient。我想做的是将Mono 实例转换为Either。
Either 实例是通过在WebClient 的响应成功时调用Either.right(..) 或在WebClient 返回错误时调用Either.left(..) 创建的。
我正在寻找的是Mono 中类似于Either.fold(..) 的方法,我可以在其中映射成功和错误的结果并返回与Mono 不同的类型。像这样的东西(伪代码不起作用):
val either : Either<Throwable, ClientResponse> =
webClient().post().exchange()
.fold({ throwable -> Either.left(throwable) },
{ response -> Either.right(response)})
应该怎么做?
【问题讨论】:
标签: kotlin spring-webflux project-reactor arrow-kt