dnowak
05/18/2021, 10:52 AMIO {
//something may throw exception here
}.handleError { t ->
//map exception to some result
}Patrick Louis
05/18/2021, 10:58 AMeither.runCatching {
// do something
}.mapLeft {
// Handle thrown exception
}Patrick Louis
05/18/2021, 10:59 AMmapLeft part could also be done with
.fold(
{ // handle exception
},
{ // handle success
}
)dnowak
05/18/2021, 11:03 AMEither<E, A almost every where so in the old IO times when I had IO<Either<E, A>> then in handleError I only had to transform Exception into some left value.
Either.catch in that case will return Either<Throwable, Either<E, A>>dnowak
05/18/2021, 11:03 AMmapLeft will leave me with Either<E, Either<E, A>>dnowak
05/18/2021, 11:06 AMfold({mapError(it)}, ::identity}Patrick Louis
05/18/2021, 11:08 AMmapLeft-version with bind(), so
either<e,a> {
val successResult = either.runCatching {
// do something
}.mapLeft { mapError(it) }.bind()
}Patrick Louis
05/18/2021, 11:09 AMmapError has type (Throwable)->Ednowak
05/18/2021, 11:13 AM