When I have a function context(EffectScope<Erro...
# arrow
k
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
yes, you only need to call
bind
when you need to consume an
Either
within an
EffectScope
k
A lot of my functions that interact with APIs I don't own look like
Copy code
fun doSomething(): Either<MyError, T> = Either.catch { ... }.mapLeft { MyError }
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?
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
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
EffectScope
k
Yeah, I can do that.