Ifvwm
04/20/2021, 8:21 AMeither { ... } ?
I can't find documents about it, related to
Either.fx<A,B> { ... } ?
simon.vergauwen
04/20/2021, 8:24 AMEither.fx
but it no longer uses the Monad
interface underneath and works much more efficiently.
The either { }
version also allows for suspension to go through, which wasn't the case with fx
.
If you want a DSL that returns immediately instead of doing suspend
there is also either.eager { }
.Ifvwm
04/20/2021, 8:36 AMsimon.vergauwen
04/20/2021, 8:41 AMEither.fx
, and you can use it exactly the same as Either.fx
. Actually, either { }
is more powerful than Either.fx
and can do more.Ifvwm
04/20/2021, 8:49 AMIO.fx {
continueOn(main)
effect { updateUI }.bind()
continueOn(backgroud)
effect { doIO }.bind()
}
if with
suspend () -> Either<A,B>
how to express that inside
either { ... }?
continueOn is available inside either ?simon.vergauwen
04/20/2021, 9:14 AMcontinueOn
is not available anymore in favor of withContext
from KotlinX.
either {
withContext(main) { updateUI.bind() }
withContext(background) { doIO.bind() }
}
simon.vergauwen
04/20/2021, 9:15 AMupdateUI
and doIO
return Either
and/or are suspend
Ifvwm
04/20/2021, 9:38 AMunsafeRunAsync
KotlinX has
CoroutineScope.async(<http://Dispatchers.IO|Dispatchers.IO>) {...}
for async IO, how to do that inside
either {...}?
simon.vergauwen
04/20/2021, 9:49 AMval res: Either<Stirng, Int> =
either<String, Int> {
val task: Deferred<Either<String, Int>> = scope.async(<http://Dispatchers.IO|Dispatchers.IO>) { delay(1000); 1.right() }
...
task.await().bind()
}
Ifvwm
04/20/2021, 10:19 AMrunBlocking { ... }
is also availabel inside either { ... } just like scope.async?simon.vergauwen
04/20/2021, 12:16 PM