stepango
03/04/2018, 3:33 PMsuspend fun <T : Any> IO<T>.await(): Either<Throwable, T> = suspendCoroutine { cont ->
unsafeRunAsync {
it.fold(
{ cont.resume(it.left()) },
{ cont.resume(it.right()) }
)
}
}
stepango
03/04/2018, 3:34 PMarrow-effects-kotlinx-coroutines
raulraja
03/04/2018, 10:10 PMval result = DeferredK<Int> = DeferredK.monad.binding {
val a = async { 1 }.k().bind()
val b = async { 1 }.k().bind()
a + b
}
or gathering async parallel results:
val remoteA = async { 1 }.k()
val remoteB = async { '1' }.k()
val remoteC = async { "1" }.k()
val result: DeferredK<Response> = DeferredK.applicative().map(
remoteA, remoteB, remoteC, { (a, b, c) ->
Response(a, b, c)
})
raulraja
03/04/2018, 10:10 PMstepango
03/05/2018, 1:36 AM