Hrafn Thorvaldsson
07/01/2022, 2:21 PMAdam Powell
07/01/2022, 2:26 PMTunji Dahunsi
07/01/2022, 2:38 PMIntent
is to model it in the stream. That is I never actually treat it as a side effect as thats one of the tenets of functional programming.
This is because if you’re going to go through the trouble of using sealed classes to pass events to your VM instead of just calling a method, you might as well go all the way and use a pure functional approach.
As far as examples go, I’ve linked one below this post. Each Action
(or Intent
) is mapped to a stream that modifies the state. Since the stream is backed by a Flow
I can map { }
and call suspend
functions in any of them allowing me to mutate the state inline without launching a side effect.
https://github.com/tunjid/me/blob/main/common/feature-archive-edit/src/commonMain/kotlin/com/tunjid/me/archiveedit/ArchiveEditMutator.kt#L87Hrafn Thorvaldsson
07/01/2022, 2:51 PM