GroupedFlow

interface GroupedFlow<K, T> : Flow<T> (source)

Represents a Flow of values that have a common key.

Note: A GroupedFlow will cache the items it is to emit until such time as it is subscribed to. For this reason, in order to avoid memory leaks, you should not simply ignore those GroupedFlows that do not concern you. Instead, you can signal to them that they may discard their buffers by applying an operator like take(0) to them.

Properties

Link copied to clipboard
abstract val key: K

The key that identifies the group of items emitted by this GroupedFlow.

Functions

Link copied to clipboard
fun <T> Flow<T>.ambWith(flow: Flow<T>, vararg flows: Flow<T>): Flow<T>

This function is an alias to raceWith operator.

Link copied to clipboard
fun <T> Flow<T>.bufferCount(bufferSize: Int): Flow<List<T>>

Buffers the source Flow values until the size hits the maximum bufferSize given.

fun <T> Flow<T>.bufferCount(bufferSize: Int, startBufferEvery: Int): Flow<List<T>>

Buffers a number of values from the source Flow by bufferSize then emits the buffer and clears it, and starts a new buffer each startBufferEvery values.

Link copied to clipboard
inline fun <R> Flow<*>.cast(): Flow<R>

Adapt this Flow to be a Flow<R>.

Link copied to clipboard
inline fun <T : Any> Flow<T?>.castNotNull(): Flow<T>

Adapt this Flow<T?> to be a Flow<T>.

Link copied to clipboard
inline fun <T> Flow<T>.castNullable(): Flow<T?>

Adapt this Flow<T> to be a Flow<T?>.

Link copied to clipboard
fun <T> Flow<T>.catchAndResume(fallbackSupplier: suspend (cause: Throwable) -> Flow<T>): Flow<T>

Catches exceptions in the flow completion and emits all the items provided by fallbackSupplier. If the fallback flow also throws an exception, the exception is not caught and is rethrown.

Catches exceptions in the flow completion and emits all the items from the fallback flow. If the fallback flow also throws an exception, the exception is not caught and is rethrown.

Link copied to clipboard

Catches exceptions in the flow completion and emits a single item, then completes normally.

fun <T> Flow<T>.catchAndReturn(itemSupplier: suspend (cause: Throwable) -> T): Flow<T>

Catches exceptions in the flow completion and emits a single item provided by itemSupplier, then completes normally.

Link copied to clipboard
fun <T> Flow<T>.chunked(bufferSize: Int): Flow<List<T>>

This function is an alias to bufferCount operator.

Link copied to clipboard
abstract suspend fun collect(collector: FlowCollector<T>)
Link copied to clipboard
fun <T> Flow<T>.concatWith(others: Iterable<Flow<T>>): Flow<T>
fun <T> Flow<T>.concatWith(others: Sequence<Flow<T>>): Flow<T>
fun <T> Flow<T>.concatWith(flow: Flow<T>): Flow<T>
fun <T> Flow<T>.concatWith(flow: Flow<T>, vararg others: Flow<T>): Flow<T>
fun <T> Flow<T>.concatWith(flow1: Flow<T>, flow2: Flow<T>): Flow<T>
fun <T> Flow<T>.concatWith(flow1: Flow<T>, flow2: Flow<T>, flow3: Flow<T>): Flow<T>
fun <T> Flow<T>.concatWith(flow1: Flow<T>, flow2: Flow<T>, flow3: Flow<T>, flow4: Flow<T>): Flow<T>

Returns a Flow that emits the items emitted from the current Flow, then the next, one after the other, without interleaving them.

Link copied to clipboard

Converts a Flow of Event objects into the emissions that they represent.

Link copied to clipboard
inline fun <T> Flow<T>.dropUntil(notifier: Flow<Any?>): Flow<T>

This function is an alias to skipUntil operator.

Link copied to clipboard
inline fun <T> Flow<Flow<T>>.exhaustAll(): Flow<T>

This function is an alias to flattenFirst operator.

Link copied to clipboard
fun <T, R> Flow<T>.exhaustMap(transform: suspend (value: T) -> Flow<R>): Flow<R>

This function is an alias to flatMapFirst operator.

Link copied to clipboard
fun <T, R> Flow<T>.flatMapConcatEager(concurrency: Int = DEFAULT_CONCURRENCY, bufferSize: Int = Channel.BUFFERED, transform: suspend (value: T) -> Flow<R>): Flow<R>

Transforms elements emitted by the original flow by applying transform, that returns another flow, and then merging and flattening these flows.

Link copied to clipboard
fun <T, R> Flow<T>.flatMapFirst(transform: suspend (value: T) -> Flow<R>): Flow<R>

Projects each source value to a Flow which is merged in the output Flow only if the previous projected Flow has completed. If value is received while there is some projected Flow sequence being merged, it will simply be ignored.

Link copied to clipboard
fun <T> Flow<Flow<T>>.flattenConcatEager(concurrency: Int = DEFAULT_CONCURRENCY, bufferSize: Int = Channel.BUFFERED): Flow<T>

Flattens the given flow of flows into a single flow in a sequential manner, without interleaving nested flows. But unlike flattenConcat collecting nested flows performed concurrently with a given concurrency limit on the number of concurrently collected flows.

Link copied to clipboard
fun <T> Flow<Flow<T>>.flattenFirst(): Flow<T>

Converts a higher-order Flow into a first-order Flow by dropping inner Flow while the previous inner Flow has not yet completed.

Link copied to clipboard
fun <T, K> Flow<T>.groupBy(bufferSize: Int = Channel.BUFFERED, keySelector: suspend (T) -> K): Flow<GroupedFlow<K, T>>
fun <T, K, V> Flow<T>.groupBy(bufferSize: Int = Channel.BUFFERED, keySelector: suspend (T) -> K, valueSelector: suspend (T) -> V): Flow<GroupedFlow<K, V>>

Groups the items emitted by the current Flow according to a specified criterion, and emits these grouped items as GroupedFlows.

Link copied to clipboard

Ignores all elements emitted by the source Flow, only passes calls of complete or error.

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

Returns a flow containing the results of applying the given transform function. Transformations performed parallel with given concurrency limit and preserving the order of elements.

Link copied to clipboard
fun <T, R> Flow<T>.mapIndexed(transform: suspend (index: Int, value: T) -> R): Flow<R>

Returns a flow containing the results of applying the given transform function to each value and its index in the original flow.

Link copied to clipboard
fun <T, R> Flow<Result<T>>.mapResultCatching(transform: suspend (T) -> R): Flow<Result<R>>

Maps a Flow of Results to a Flow of a mapped Results.

Link copied to clipboard
inline fun <T, R> Flow<T>.mapTo(value: R): Flow<R>

Emits the given constant value on the output Flow every time the source Flow emits a value.

Link copied to clipboard

Maps values in the Flow to successful results, and catches and wraps any exception into a failure result.

Link copied to clipboard
inline fun <T> Flow<T>.mapToUnit(): Flow<Unit>

Emits kotlin.Unit value on the output Flow every time the source Flow emits a value.

Link copied to clipboard
fun <T> Flow<T>.materialize(): Flow<Event<T>>

Represents all of the notifications from the source Flow as value emissions marked with their original types within Event objects.

Link copied to clipboard
fun <T> Flow<T>.pairwise(): Flow<Pair<T, T>>

Groups pairs of consecutive emissions together and emits them as a pair.

fun <T, R> Flow<T>.pairwise(transform: suspend (a: T, b: T) -> R): Flow<R>

Groups pairs of consecutive emissions together and emits the result of applying transform function to each pair.

Link copied to clipboard
operator fun <T> Flow<T>.plus(other: Flow<T>): Flow<T>

This function is an alias to concatWith operator.

Link copied to clipboard
fun <T> Flow<T>.raceWith(flow: Flow<T>, vararg flows: Flow<T>): Flow<T>

Mirrors the current Flow or the other Flows provided of which the first either emits a value or sends a termination event (error or complete event).

Link copied to clipboard
fun <T> Flow<T>.repeat(): Flow<T>

Returns a Flow that repeats all values emitted by the original Flow indefinitely.

fun <T> Flow<T>.repeat(count: Int): Flow<T>

Returns a Flow that repeats all values emitted by the original Flow at most count times. If count is zero or negative, the resulting Flow completes immediately without emitting any items (i.e. emptyFlow).

fun <T> Flow<T>.repeat(delay: suspend (count: Int) -> Duration): Flow<T>

Returns a Flow that repeats all values emitted by the original Flow indefinitely, with a delay computed by delay function between each repetition.

fun <T> Flow<T>.repeat(delay: Duration): Flow<T>
fun <T> Flow<T>.repeat(count: Int, delay: Duration): Flow<T>

Returns a Flow that repeats all values emitted by the original Flow indefinitely, with a fixed delay between each repetition.

fun <T> Flow<T>.repeat(count: Int, delay: suspend (count: Int) -> Duration): Flow<T>

Returns a Flow that repeats all values emitted by the original Flow at most count times, with a delay computed by delay function between each repetition.

Link copied to clipboard
fun <T> Flow<T>.retryWhenWithDelayStrategy(strategy: DelayStrategy, predicate: suspend FlowCollector<T>.(cause: Throwable, attempt: Long) -> Boolean): Flow<T>

Retries collection of the given flow when an exception occurs in the upstream flow and the predicate returns true. The predicate also receives an attempt number as parameter, starting from zero on the initial call. When predicate returns true, the next retries will be delayed after a duration computed by DelayStrategy.nextDelay.

Link copied to clipboard
fun <T> Flow<T>.retryWhenWithExponentialBackoff(initialDelay: Duration, factor: Double, maxDelay: Duration = Duration.INFINITE, predicate: suspend FlowCollector<T>.(cause: Throwable, attempt: Long) -> Boolean): Flow<T>

Retries collection of the given flow with exponential backoff delay strategy when an exception occurs in the upstream flow and the predicate returns true. When predicate returns true, the next retries will be delayed after a duration computed by DelayStrategy.ExponentialBackoffDelayStrategy.

Link copied to clipboard
fun <T> Flow<T>.retryWithExponentialBackoff(initialDelay: Duration, factor: Double, maxAttempt: Long = Long.MAX_VALUE, maxDelay: Duration = Duration.INFINITE, predicate: suspend (cause: Throwable) -> Boolean = { true }): Flow<T>

Retries collection of the given flow with exponential backoff delay strategy when an exception occurs in the upstream flow and the predicate returns true. When predicate returns true, the next retries will be delayed after a duration computed by DelayStrategy.ExponentialBackoffDelayStrategy.

Link copied to clipboard
inline fun <R> Flow<*>.safeCast(): Flow<R?>

Adapt this Flow<*> to be a Flow<R?>. At the collection time, if this Flow has any value that is not an instance of R, null will be emitted.

Link copied to clipboard
fun <T, R> Flow<T>.scanWith(initialSupplier: suspend () -> R, operation: suspend (accumulator: R, value: T) -> R): Flow<R>

Folds the given flow with operation, emitting every intermediate result, including the initial value supplied by initialSupplier at the collection time.

Link copied to clipboard

Select a sub-state from the State and emit it if it is different from the previous one.

fun <State, SubState1, SubState2, Result> Flow<State>.select(selector1: Selector<State, SubState1>, selector2: Selector<State, SubState2>, projector: suspend (subState1: SubState1, subState2: SubState2) -> Result): Flow<Result>

Select two sub-states from the source Flow and combine them into a Result.

fun <State, SubState1, SubState2, SubState3, Result> Flow<State>.select(selector1: Selector<State, SubState1>, selector2: Selector<State, SubState2>, selector3: Selector<State, SubState3>, projector: suspend (subState1: SubState1, subState2: SubState2, subState3: SubState3) -> Result): Flow<Result>

Select three sub-states from the source Flow and combine them into a Result.

fun <State, SubState1, SubState2, SubState3, SubState4, Result> Flow<State>.select(selector1: Selector<State, SubState1>, selector2: Selector<State, SubState2>, selector3: Selector<State, SubState3>, selector4: Selector<State, SubState4>, projector: suspend (subState1: SubState1, subState2: SubState2, subState3: SubState3, subState4: SubState4) -> Result): Flow<Result>

Select four sub-states from the source Flow and combine them into a Result.

fun <State, SubState1, SubState2, SubState3, SubState4, SubState5, Result> Flow<State>.select(selector1: Selector<State, SubState1>, selector2: Selector<State, SubState2>, selector3: Selector<State, SubState3>, selector4: Selector<State, SubState4>, selector5: Selector<State, SubState5>, projector: suspend (subState1: SubState1, subState2: SubState2, subState3: SubState3, subState4: SubState4, subState5: SubState5) -> Result): Flow<Result>

Select five sub-states from the source Flow and combine them into a Result.

Link copied to clipboard
fun <T> Flow<T>.skipUntil(notifier: Flow<Any?>): Flow<T>

Returns a Flow that skips items emitted by the source Flow until a second Flow emits a value or completes.

Link copied to clipboard
fun <T> Flow<T>.startWith(item: T): Flow<T>

Returns a Flow that emits a specified item before it begins to emit items emitted by the current Flow.

fun <T> Flow<T>.startWith(others: Iterable<T>): Flow<T>
fun <T> Flow<T>.startWith(others: Sequence<T>): Flow<T>
fun <T> Flow<T>.startWith(item1: T, item2: T): Flow<T>
fun <T> Flow<T>.startWith(item: T, vararg items: T): Flow<T>
fun <T> Flow<T>.startWith(item1: T, item2: T, item3: T): Flow<T>
fun <T> Flow<T>.startWith(item1: T, item2: T, item3: T, item4: T): Flow<T>
fun <T> Flow<T>.startWith(item1: T, item2: T, item3: T, item4: T, item5: T): Flow<T>

Returns a Flow that emits the specified items before it begins to emit items emitted by the current Flow.

fun <T> Flow<T>.startWith(itemFactory: suspend () -> T): Flow<T>

Returns a Flow that emits a specified item before it begins to emit items emitted by the current Flow. itemFactory will be called on the collection for each new FlowCollector.

fun <T> Flow<T>.startWith(other: Flow<T>): Flow<T>

Returns a Flow that emits the items in a specified Flow before it begins to emit items emitted by the current Flow.

Link copied to clipboard
fun <T> Flow<T>.takeUntil(notifier: Flow<Any?>): Flow<T>

Emits the values emitted by the source Flow until a notifier emits a value or completes.

Link copied to clipboard
fun <T> Flow<T>.throttleTime(throttleConfiguration: ThrottleConfiguration = LEADING, durationSelector: (value: T) -> Duration): Flow<T>

Returns a Flow that emits a value from the source Flow, then ignores subsequent source values for a duration determined by durationSelector, then repeats this process for the next source value.

fun <T> Flow<T>.throttleTime(timeMillis: Long, throttleConfiguration: ThrottleConfiguration = LEADING): Flow<T>

Returns a Flow that emits a value from the source Flow, then ignores subsequent source values for timeMillis milliseconds, then repeats this process for the next source value.

fun <T> Flow<T>.throttleTime(duration: Duration, throttleConfiguration: ThrottleConfiguration = LEADING): Flow<T>

Returns a Flow that emits a value from the source Flow, then ignores subsequent source values for a duration, then repeats this process for the next source value.

Link copied to clipboard

Maps a Flow of Results to a Flow of values from successful results. Failure results are re-thrown as exceptions.

Link copied to clipboard
inline fun <A, B> Flow<A>.withLatestFrom(other: Flow<B>): Flow<Pair<A, B>>

fun <A, B, R> Flow<A>.withLatestFrom(other: Flow<B>, transform: suspend (A, B) -> R): Flow<R>

Merges two Flows into one Flow by combining each value from self with the latest value from the second Flow, if any. Values emitted by self before the second Flow has emitted any values will be omitted.

Link copied to clipboard
fun <T> Flow<T>.zipWithNext(): Flow<Pair<T, T>>
fun <T, R> Flow<T>.zipWithNext(transform: suspend (a: T, b: T) -> R): Flow<R>

This function is an alias to pairwise operator.