Package-level declarations

Flow operators and StateFlow helpers.

Start here:

  • throttleFirst: let one value through, then ignore values for a while.

  • mapAsync: map a flow with many calls at the same time, in order.

  • mapState: derive a StateFlow from a StateFlow, without a CoroutineScope.

  • combineStates: combine two to four StateFlows into one.

Functions

Link copied to clipboard
fun <A, B, R> combineStates(a: StateFlow<A>, b: StateFlow<B>, transform: (A, B) -> R): StateFlow<R>

Like combine for two StateFlows, but the result is a StateFlow, and no CoroutineScope is needed.

fun <A, B, C, R> combineStates(a: StateFlow<A>, b: StateFlow<B>, c: StateFlow<C>, transform: (A, B, C) -> R): StateFlow<R>

The three-source form of combineStates. The same rules apply.

fun <A, B, C, D, R> combineStates(a: StateFlow<A>, b: StateFlow<B>, c: StateFlow<C>, d: StateFlow<D>, transform: (A, B, C, D) -> R): StateFlow<R>

The four-source form of combineStates. The same rules apply.

Link copied to clipboard
fun <T, R> Flow<T>.mapAsync(concurrency: Int, transform: suspend (T) -> R): Flow<R>

Like map, but runs up to concurrency calls of transform at the same time. The output keeps the input order.

Link copied to clipboard
fun <T, R> StateFlow<T>.mapState(transform: (T) -> R): StateFlow<R>

Like map for a StateFlow, but the result is still a StateFlow, and no CoroutineScope is needed.

Link copied to clipboard
fun <T> Flow<T>.throttleFirst(window: Duration): Flow<T>

Emits a value, then ignores new values until window has passed. For taps and other bursts.