Hi, I'm new to arrow and already passionate, and t...
# arrow
r
Hi, I'm new to arrow and already passionate, and try to use IO with Either to have a typed error but I'm stuck with the composition of dependent function like:
Copy code
fun 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?
i
you need EitherT if you want to compute in a context where Either is inside another monad (in your case IO), https://arrow-kt.io/docs/0.10/arrow/mtl/eithert/
j
That's a good option also
r
thank a lot you for the suggestions, I try to understand and follow this approach
i
the syntax can be quite hard to figure out first, but in the example case it would go something like this with 0.10.5 syntax ...
Copy code
data 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()
r
thank you so much very helpful