Chris Paul
02/01/2021, 3:18 PMval result: Either<VdsError, VdsData>
and these error data types:
sealed class VdsError {
object NotFound: VdsError()
object SystemError: VdsError()
}
is there a simple way to map on success, but also on NotFound
, but break out of the mapping if SystemError
?
eg
result.map { data ->
doSomething()
data
}
basically conditionally map some failure circumstances but ignore others?
I thought perhaps a conditional mapLeft would do this, but the problem is that mapLeft
then returns a Left
rather than a Right
and then you immediately exit
hope this makes sense, I'm still quite new to these sort of functional types.Chris Paul
02/01/2021, 3:22 PMEither<VdsError, VdsData?>
and then eliminating the NotFound
error but I feel like there should be another solutionaballano
02/01/2021, 3:22 PMhandleErrorWith
witch should do what you want if you add a conditional check for the NotFoundChris Paul
02/01/2021, 3:23 PMaballano
02/01/2021, 3:24 PMresult.handleErrorWith {
if (it == NotFound) //recover
else it.left()
}
Chris Paul
02/01/2021, 3:24 PMChris Paul
02/01/2021, 3:24 PMHaris Khan
02/01/2021, 3:55 PMChris Paul
02/01/2021, 4:03 PMHaris Khan
02/01/2021, 4:17 PM