aballano
04/01/2019, 4:48 PMIO<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
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 })
}
}
pakoito
04/01/2019, 5:49 PMifRight = { just(it) })
aballano
04/01/2019, 9:01 PMifRight = { just(it.right()) })