6

请教一下函数式中 either monad 的使用方法

 3 years ago
source link: https://www.v2ex.com/t/787095
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

V2EX  ›  程序员

请教一下函数式中 either monad 的使用方法

  yazinnnn · 19 小时 0 分钟前 · 182 次点击
//自定义异常
sealed class MyE : RuntimeException()
object AE : MyE()
object BE : MyE()

//业务方法签名
fun a(): Either<AE, Int>
fun b(i: Int): Either<BE, Int>

方法调用
val a: Either<AE, Int> = a()

//a.map{} 之后的类型会变成 Either<AE, Either<BE, Int>>
val either: Either<AE, Either<BE, Int>> = a.map { b(it) }

请问有什么函数能返回 Either<MyE,Int> 吗?


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK