When I have a function context(EffectScope<Error>) suspend fun foo(): T. If I call foo() inside an either {} block I don't need to call .bind() and everything works as expected, correct?
a
Alejandro Serrano Mena
12/29/2022, 1:27 PM
yes, you only need to call
bind
when you need to consume an
Either
within an
EffectScope
k
Kristian Nedrevold
12/29/2022, 1:47 PM
A lot of my functions that interact with APIs I don't own look like
When using EffectScope<Error> what would be an equivalent ?
Copy code
context(EffectScope<MyError>) suspend fun doSomething(): T = try { ... } catch { shift(MyError) }
Is what I have now when I want to map the exception to an error type in the function.
Copy code
context(EffectScope<MyError>) suspend fun doSomething(): T = ...
effect { doSomething() }.fold(
error = { ... } ...
How I handle the exception if I want to handle it at the caller. Is this the "intended" way of doing this?
Kristian Nedrevold
12/29/2022, 1:49 PM
The last way is what seems to be the obviously idiomatic way of doing it, but it also requires that exceptions are exceptional, which they often aren't.
a
Alejandro Serrano Mena
12/29/2022, 2:55 PM
may I suggest you to open a discussion in the repo? this seems like an interesting use for a new combinator in which we wrap an exceptional function and use it inside an