If i have an either: `val result: Either<VdsErr...
# arrow
c
If i have an either:
val result: Either<VdsError, VdsData>
and these error data types:
Copy code
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
Copy code
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.
I can side step the problem by changing it
Either<VdsError, VdsData?>
and then eliminating the
NotFound
error but I feel like there should be another solution
a
for Either you have
handleErrorWith
witch should do what you want if you add a conditional check for the NotFound
c
hmm
a
Copy code
result.handleErrorWith {
  if (it == NotFound) //recover
  else it.left()
}
👍 1
c
couldn't find that in the docs
that is very useful thankyou
👍 1
h
@Chris Paul If you're looking for docs on it: https://arrow-kt.io/docs/arrow/typeclasses/applicativeerror/
c
yea i found that after I googled Alberto's answer. It's good to have that documentation, but I only found it once I knew what I was looking for
h
It's certainly a miss that it's not on the page with Either, I agree.