thanh
04/27/2022, 9:04 AMfutureOr
function:
suspend fun fu(i: Int): Boolean = TODO()
suspend fun futureOr(fs: List<Int>): Boolean =
fs.parTraverse { fu(it) }.reduce { acc, b -> acc || b }
Now it needs to wait for all of suspend function completed. But we know that if there is one of the fu(it)
return false
we can return false
and cancel the rest. Not sure how to do it nicely here.simon.vergauwen
04/27/2022, 9:32 AMsimon.vergauwen
04/27/2022, 9:35 AMsuspend fun fu(i: Int): Boolean = TODO()
suspend fun futureOr(fs: List<Int>): Boolean =
effect<Unit, Unit> {
fs.parTraverse {
if(fu(it)) Unit else shift(Unit)
}
}.fold({ false }, { true })
simon.vergauwen
04/27/2022, 9:35 AMshift
makes the parTraverse
short-circuit.simon.vergauwen
04/27/2022, 9:35 AMeither { }
from 1.x.xthanh
04/27/2022, 9:52 AMsimon.vergauwen
04/27/2022, 9:54 AMjulian
04/27/2022, 6:43 PMshift
, effect
- These are new to me. Where may I read more about them?julian
04/27/2022, 6:56 PMsimon.vergauwen
04/28/2022, 7:06 AMEffect
type, and might give you some more insights.
It's new, but also not new 😄 It works 95% the same as either { }
, and either { }
is now build on top of effect { }
.simon.vergauwen
04/28/2022, 7:07 AMsuspend fun <E, A> either(f: suspend EffectScope<E>.() -> A): Either<E, A> = effect(f).toEither()
and shift(e) <~~> e.left().bind()
simon.vergauwen
04/28/2022, 7:08 AMjulian
04/28/2022, 5:33 PM