<https://github.com/arrow-kt/arrow/pull/2540>
# arrow-contributors
p
k
we are planning to do a different
bind
solution on extra requirements in our android state management. We wanted to bring in
Async
work into our scope and also provide an environment for the binding. something similar:
Copy code
public suspend fun <E : Environment, ER, R> EitherScope<E, ER>.bind(
    f: suspend E.() -> Either<R, ER>,
) : R

public suspend fun <E : Environment, ER, R> EitherScope<E, ER>.bindAsync(
    f: suspend E.() -> Either<R, ER>,
) : Deferred<R>
instead of binding on the
Either
type we bind on the scope and the bind argument return value will be evaluated. usage:
Copy code
either {
    val a = bind { this.myNetworkCall() }
    val b = bindAsync { this.myNetworkCall2() }
    b.await()
}
we baked in our Error type but could effectively provide a mapper for as the first argument.
Copy code
bind({ it.message }) { myCall() }
p
Isn't that Either.catch? with
.bind
k
yeah it is 👍
Copy code
val env = getEnvironment()
val a = Either.catch { env.networkCall() }.bind()
our usecase requires the environment so we could add it in scope 🙂
having async also adds quite a lot of nesting so we aimed to reduce the required setup
Copy code
coroutineScope {
    val env = getEnvironment()
    val a = async { Either.catch { env.networkCall() }.bind() }
}