-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add bridge from Throwable to E for ApplicativeError #4286
Comments
This is really interesting!
This doesn't seem right to me. Exception-throwing code should ideally never be written outside of a It seems to me what you actually want is maybe something like In which case I think you want something like this? F.catchNonFatal(doTheThing()).map(G.pure).recover {
case ex: MyAdaptableException => G.raiseError(whatever)
} Maybe a dedicated method/syntax could make that a bit neater. I'm not entirely sure where it could live. While writing this, I noticed cats/core/src/main/scala/cats/ApplicativeError.scala Lines 263 to 267 in bf216a4
|
If I understand the existing I could be missing something though. The local helper this grew out of did originally require the adapting function to be total, so I'm certainly am not opposed to this approach. |
@armanbilge I'm still on the fence for |
Interacting with code that can throw exceptions can be awkward when working with
ApplicativeError
ifE
isn'tThrowable
, because theApplicativeError#catch*
methods don't really have a way to bridge intoF
unless you know whatF
is.You can absolutely make it work, you just can't really leverage the
ApplicativeError#catch*
helpers, which is a shame because they're really handy, and I think it would be really straightforward to offer alternatives that are more generally applicable.I propose adding parallel methods which would allow adapting a
Throwable
to anE
. For example,ApplicativeError#catchNonFatalAs
could look like this:Similar methods could be created for
ApplicativeError#catchNonFatalEval
andApplicativeError#catchOnly
.The text was updated successfully, but these errors were encountered: