I use arrow-kt library and I'm trying to employ Either
and IO
within the same for comprehension.
Say I have the next piece of code:
IO.monad().binding {
val ans: Either<Error, Data> = someFunctionThatReturnsEitherWrappedInIO().bind()
}
Now, I'd like to use binding on the ans
:
val data: Data = ans.bind() // My intent
Is it possible to do It whithin the scope of the first piece of code?
Currently I'm trying to nest an Either
binding within the scope of the IO binding, but I'm not sure this is a good practice:
IO.monad().binding {
val ans: Either<Error, Data> = someFunctionThatReturnsEitherWrappedInIO().bind()
val ansB: Either<Error, OtherData> = someOtherFunctionThatReturnsEitherWrappedInIO().bind()
val newData: Either<Any, NewData> = Either.monad<Any>().binding {
val data: Data = ans.bind()
val otherData: OtherData = ansB.bind()
NewData(data.a, otherData.lala)
}.fix()
}