Hey, anybody knows why the `catch` function from t...
# arrow
a
Hey, anybody knows why the
catch
function from the
Either
is a suspend function? Is it possible to catch an exception without using an
IO
?
s
Yes, since
suspend
models a
Continuation
which results in
Throwable
or
A
. Similar to how
IO
results in
Throwable
or
A
.
The default constructor for
IO
is equivalent to
fun <A> IO(f: suspend () -> A): IO<A>
.
And so you could capture the result safely in
IO
and flatten it. Or any other
suspend
implementation
a
okay,thanks for the answer! I was asking because since Try was deprecated maybe makes sense to do the same but without the limitation of a suspend... But maybe, doesn't makes sense because it is a side effect... 🤔
p
yyyyyep that’s why we did it 😄
👍 1