【发布时间】:2020-07-20 04:45:49
【问题描述】:
我有简单的三个函数返回 arrow-kt 数据类型
fun validate(input): Validated<Error, Input> = ...
fun fetch(input): Option<Error, InputEntity> = ...
fun performAction(inputEntity): Either<Error, Output> = ...
并且想要链接这样的东西(可以使用任何可用的函数而不是map)
validate(input)
.map{fetch(it)}
.map{performAction(it)}
我能想出的唯一解决方案是将Validated 和Option 替换为Either,并使用flatMap 进行链接。有没有更好的功能方法让它在不更新现有功能的情况下工作?
【问题讨论】:
标签: kotlin functional-programming arrow-kt