Skip to content

Instantly share code, notes, and snippets.

@tunjid
Created January 7, 2022 15:20
Show Gist options
  • Save tunjid/d951cb206dd59e395d6514a1721c41f2 to your computer and use it in GitHub Desktop.
Save tunjid/d951cb206dd59e395d6514a1721c41f2 to your computer and use it in GitHub Desktop.
fun <Action : Any, State : Any> Flow<Action>.toStateStream(
initialState: State,
transform: (Flow<Action>) -> Flow<State.() -> State>
): Flow<State> = transform(this)
.scan(initialState) { state, mutation ->
mutation(state)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment