I am confused as to why `Either.catch()` requires ...
# arrow
e
I am confused as to why
Either.catch()
requires a suspend function
r
suspend denotes an effect and exceptions are effects. If they don't run within suspend they will blow up uncontrolled but when they are suspend there is always a continuation that is responsible for error handling in that context.
e
So what is the proper way to use
Either.catch()
?
r
The function surrounding it should also be suspend
You can manually create a function though without suspend that uses try/catch and lifts to left and right before it exits
If you want an unsafe version of it
e
So
MonadError.catch()
is unsafe?
If I surround
Either.catch()
with
runBlocking { }
is that safe?
r
There is effectCatch that is the suspend version
If you chain suspend is safe until the point you do runBlocking or similar
e
Ok thanks
👍 1
r
The unsafe part is not so much related to the exception potentially blowing up as it is that any effect in the function will run
Because Either is strict and effects run before they can be placed in left or right
For lazy evaluation and composition we recommend IO which is pure across the board even with concurrency and async jumps and manages errors with guarantees