CLOVIS
10/18/2022, 1:36 PMbind
abstraction is implemented? I'd like to adapt it to a StateFlow (essentially the same as Either's with success and error, but the value changes over time).simon.vergauwen
10/18/2022, 1:42 PMFlow
since that requires multiple calls to Continuation#resume
, we've tried many different ways and were never able to figure out an implementation for Flow
.
I've been trying to document as much of Arrow's design and there is quite a lot of information on the design for Arrow 2.x.x here, https://github.com/arrow-kt/arrow/pull/2797CLOVIS
10/18/2022, 1:43 PMsimon.vergauwen
10/18/2022, 1:43 PMCLOVIS
10/18/2022, 1:44 PMFlow<Either<AppError, T>>
and I'm trying to figure out a proper API so it's convenient to use... Do you have any recommendations/clues?simon.vergauwen
10/18/2022, 1:46 PMfun <E, A> Flow<Either<E, A>>.mapEither(transform: EffectScope<E>.(A) -> B): Flow<Either<E, B>> =
map { original ->
either<E, B> {
transform(this, original.bind())
}
}
simon.vergauwen
10/18/2022, 1:48 PMval original: Flow<Either<AppError, String>> = TODO()
val mapped: Flow<Either<AppError, Int>> =
original.mapEither { string ->
ensureNotNull(string.toIntOrNull()) {
AppError.ConversionFailed
}
}
simon.vergauwen
10/18/2022, 1:48 PMmapEither
transparently gives you access to the entire either { }
DSL.CLOVIS
10/18/2022, 1:48 PMraulraja
10/18/2022, 1:49 PMcontext(FlowCollector<A>, Raise<E>)
suspend fun foo(): B {
emit(a)
raise(e)
return b
}
maybe it's possible to create a Flow subtype that types it's error and can be used as single receiversimon.vergauwen
10/18/2022, 1:51 PMCLOVIS
10/20/2022, 7:55 AM@Composable
world with things like Molecule, do you think it's possible to get the same early-return behavior as with either
? If I understand correctly either
works using the internal suspend
machinery, which I don't think Composables
have 🤔simon.vergauwen
10/29/2022, 3:38 PMResult<A>
), and you can make scoped cheap exceptions similar to GOTO mechanism.
This is what is used in Flow#take
for early-returns, kotlinx.coroutines.Job
for cancellation and also for Arrow’s DSLs.
I’m not familiar enough with @Composeable
to give you a concrete example, or reply, but I’m not sure why it would not work 🤔
I think the biggest hurdle is that @Composable
by-passes the type-system, no? Rather than action: Composable.() -> A
CLOVIS
10/29/2022, 5:59 PM@Composable
function cannot suspend
... I'll see what I can manage with Composables that return Either
.
I'm especially interested because unlike suspend functions, Composable functions do not transmit their exceptions cleanly up the call stack, so there's no alternative for error managementsimon.vergauwen
10/30/2022, 9:49 AMComposable functions do not transmit their exceptions cleanly up the call stackOof, that sounds tricky. In Arrow 2.x.x the
either { }
DSL will be inline
, and there will be no more need for suspend fun either { }
or either.eager { }
I am not sure if that would improve the situation? I can look into fixing the publishing of Arrow 2.x.x SNAPSHOT if you’d like to give that a try.CLOVIS
10/30/2022, 10:13 AMbind
if you're not guaranteed to be in a suspending context?CLOVIS
10/30/2022, 10:14 AMsimon.vergauwen
10/30/2022, 11:02 AMI’m not sure what you mean with that 🤔 In Kotlin Coroutines rely on exceptions (), and you can make scoped cheap exceptions similar to GOTO mechanism.Result<A>
This is what is used inBut here you can check all the implementation details, and the design discussion 🙂 Any, and all, feedback is very welcome! https://github.com/arrow-kt/arrow/pull/2797for early-returns,Flow#take
for cancellation and also for Arrow’s DSLs.kotlinx.coroutines.Job