https://kotlinlang.org logo
#arrow-contributors
Title
# arrow-contributors
a

aballano

04/01/2019, 4:48 PM
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

pakoito

04/01/2019, 5:49 PM
ifRight = { just(it) })
👍 1
a

aballano

04/01/2019, 9:01 PM
close, had to wrap into either also
ifRight = { just(it.right()) })
👍🏼 1
3 Views