hi there, I'm trying to add arrow to an example an...
# arrow-contributors
a
hi there, I'm trying to add arrow to an example android app. I'm wondering, is it possible, having an
IO<Either<E, A>>
to flatmap to another one in case the inner Either is
left
? I managed to do this, but I believe the same IO is being executed twice in case of the either is
right
Copy code
fun <E, A> IO<Either<E, A>>.handleErrorWith(f: (E) -> IO<Either<E, A>>): IO<Either<E, A>> {
    return flatMap { either ->
        either.fold(ifLeft = {
            f(it)
        }, ifRight = { this })
    }
}
p
ifRight = { just(it) })
👍 1
a
close, had to wrap into either also
ifRight = { just(it.right()) })
👍🏼 1