addSource

abstract fun <T> addSource(flow: Flow<T>, scope: CoroutineScope, block: suspend (State, T) -> State): Job

Add a source of state from another Flow.

This is useful when you need to update the state based off of another Flow. The flow will be collected and block will be invoked in order to map the T value from flow to the State value.

The collecting can be stopped by cancelling the returned Job.

Return

The Job of the collection.

Parameters

T

The type of the value from flow.

flow

The flow to collect from and update state with.

scope

The scope to use for collecting the flow.

block

The function to map the T value from flow to the State value.