6
请教一下函数式中 either monad 的使用方法
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.
//自定义异常
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> 吗?
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK