Ivan Dugalic
01/05/2023, 8:34 AMIvan Dugalic
01/05/2023, 8:35 AMIvan Dugalic
01/05/2023, 8:35 AMcontext (StateComputation<C, S, E>, StateRepository<C, S>, Raise<Error>)
suspend fun <C, S, E> C.handleWithEffect(): S =
catch({
fetchState().computeNewState(this@handleWithEffect).save()
}) {
raise(CommandHandlingFailed(this, it))
}Ivan Dugalic
01/05/2023, 8:36 AMIvan Dugalic
01/05/2023, 8:36 AMIvan Dugalic
01/05/2023, 8:36 AMcontext (StateComputation<C, S, E>, StateRepository<C, S>)
fun <C, S, E> Flow<C>.handleWithEffect(): Flow<Effect<Error, S>> =
map { effect { it.handleWithEffect() } }.catch { emit(effect { raise(CommandPublishingFailed(it)) }) }Ivan Dugalic
01/05/2023, 8:36 AMIvan Dugalic
01/05/2023, 8:36 AMcontext (StateComputation<C, S, E>, StateRepository<C, S>, Raise<Error>)
fun <C, S, E> Flow<C>.handleWithEffect2(): Flow<S> =
map { it.handleWithEffect() }.catch { raise(CommandPublishingFailed(it) ) }Ivan Dugalic
01/05/2023, 8:39 AMsimon.vergauwen
01/05/2023, 9:57 AMeffect correctly, int he second option you need to be sure that collect is called inside effect { }.Ivan Dugalic
01/05/2023, 10:08 AMIvan Dugalic
01/05/2023, 10:10 AMFlow<S> 🙂 rather then returning explicitly Flow<Effect<Error, S>>Ivan Dugalic
01/05/2023, 10:13 AMFlow<Either<Error, S>> rather then Flow<Effect<Error, S>> . What do you think? Do you see any cons of using Effect?simon.vergauwen
01/05/2023, 2:00 PMEither is definitely a good option also.
I would say that Either is better understood, and it prevents leaking raise operator. It's a good type to use in this case.
Effect has the ability to be "traced", which also might be useful. Tracing POC
Exposing both is probably not useful, since it'll result in signature clashes all over the place.