rcfgnu
04/15/2020, 11:48 AMfun x() : IO<Either<Failure,String>>
fun y(xResult: String) : IO<Either<Failure,Int>>
fun z(yResult: Int) : IO<Either<Failure,String>>
It's my design totally wrong?isto
04/15/2020, 11:55 AMJorge Castillo
04/15/2020, 11:56 AMrcfgnu
04/15/2020, 12:06 PMisto
04/15/2020, 2:15 PMisto
04/15/2020, 2:15 PMdata class Failure(val reason: String)
fun x() : IO<Either<Failure,String>> = IO { "x".right() }
fun y(xResult: String) : IO<Either<Failure,Int>> { return IO { Failure(xResult).left() } }
fun z(yResult: Int) : IO<Either<Failure,String>> { return IO { "$yResult".right() } }
fun compute(): IO<Either<Failure, String>> = EitherT.monad<Failure, ForIO>(IO.monad()).fx.monad {
val xResult = ! EitherT(x())
val yResult = ! EitherT(y(xResult))
! EitherT(z(yResult))
}.value().fix()
rcfgnu
04/15/2020, 3:04 PM