pakoito
09/28/2021, 3:36 PMkioba
09/29/2021, 11:18 AMbind
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:
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:
either {
val a = bind { this.myNetworkCall() }
val b = bindAsync { this.myNetworkCall2() }
b.await()
}
kioba
09/29/2021, 11:23 AMbind({ it.message }) { myCall() }
pakoito
09/29/2021, 1:48 PM.bind
kioba
09/29/2021, 3:37 PMval env = getEnvironment()
val a = Either.catch { env.networkCall() }.bind()
our usecase requires the environment so we could add it in scope 🙂kioba
09/29/2021, 3:39 PMcoroutineScope {
val env = getEnvironment()
val a = async { Either.catch { env.networkCall() }.bind() }
}