https://kotlinlang.org logo
#coroutines
Title
# coroutines
r

reactormonk

09/19/2023, 8:32 AM
I've got code which transforms an incoming flow and invokes actions based on basically a state machine. Currently the code does a few weird things, so I need to refactor it to be more predictable. Is there a
suspend fun Flow<R>.mapState(initial: T, fun: (T, R) -> (T, Flow<S>)): Flow<S>
somewhere?
s

Sam

09/19/2023, 9:02 AM
Can you give an example of how you would call it? There's
fold
and
runningFold
, but neither of them exactly matches the signature you wrote there.
r

reactormonk

09/19/2023, 9:03 AM
Lemme take a look at them. I'm mostly looking to make the state transfer from one iteration to the next one very explicit
f

franztesca

09/19/2023, 9:20 AM
A suspend fun that returns a flow is generally smelly btw