Hi, I'm working on an upgrade in our Android proje...
# arrow
m
Hi, I'm working on an upgrade in our Android project from a very old version of Arrow (0.8) to 0.10.2 (0.10.5 is not an option yet because of a Kotlin/Proguard issue). Some of the uses cases in the project are like this:
Copy code
suspend fun init0(): Either<Failed, Loaded>
suspend fun init1(): Either<Failed, Loaded>
suspend fun init2(): Either<Failed, Loaded>
A group of independent
suspend
functions that return `Either<Failed, Loaded>`; those functions were previously composed with using
Try.flatMap
and to be able to migrate them to
Either
I added temporarily a trapdoor function like this:
Copy code
inline fun <A, B, C> EitherOf<A, B>.flatMapInline(f: (B) -> Either<A, C>): Either<A, C> =
    fix().let {
        when (it) {
            is Either.Right -> f(it.b)
            is Either.Left -> it
        }
    }

val bootDeprecated = init0()
    .flatMapInline { init1() }
    .flatMapInline { init2() }
I want to move forward the approach, get rid of my
flatMapInline
trapdoor, and start using IO to deffer the effects. But my problem is that I don't figure out how to get the same behavior in a more expressive way. This was my best attempt:
Copy code
val boot: IO<Either<Failed, Loaded>> = IO.fx {
        !effect { init0() }
            .effectMap { if (it.isRight()) init1() else it }
            .effectMap { if (it.isRight()) init2() else it }
    }
This works (from a pragmatic perspective) and I achieve the same short-circuiting the effect if one of them fails. However, I'm wondering if there is a better built-in way to express this. Thanks so much for any advice or recommendation and sorry in advance for the long post