Package-level declarations

Types

Link copied to clipboard
fun interface DelayStrategy

Interface that computes the delay between retries.

Link copied to clipboard
annotation class DelicateFlowExtApi

Marks declarations in the FlowExt that are delicate — they have limited use-case and shall be used with care in general code. Any use of a delicate declaration has to be carefully reviewed to make sure it is properly used and does not create problems like memory and resource leaks. Carefully read documentation of any declaration marked as DelicateFlowExtApi.

Link copied to clipboard
sealed interface Event<out T>

Represents the reactive signal types: value, error and complete, and holds their parameter values (a value, a Throwable, nothing).

Link copied to clipboard

Marks FlowExt-related API as a feature preview.

Link copied to clipboard
interface GroupedFlow<K, T> : Flow<T>

Represents a Flow of values that have a common key.

Link copied to clipboard
sealed interface NeverFlow : Flow<Nothing>

A Flow that never emits any values to the FlowCollector and never completes.

Link copied to clipboard
typealias Selector<State, SubState> = suspend (State) -> SubState

Inspirited by NgRx memoized selector.

Link copied to clipboard

Define leading and trailing behavior.

Functions

Link copied to clipboard
fun <T> amb(flow1: Flow<T>, flow2: Flow<T>, vararg flows: Flow<T>): Flow<T>

This function is an alias to race operator.

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
fun <T1, T2, T3, T4, T5, T6, R> combine(flow: Flow<T1>, flow2: Flow<T2>, flow3: Flow<T3>, flow4: Flow<T4>, flow5: Flow<T5>, flow6: Flow<T6>, transform: suspend (T1, T2, T3, T4, T5, T6) -> R): Flow<R>
fun <T1, T2, T3, T4, T5, T6, T7, R> combine(flow: Flow<T1>, flow2: Flow<T2>, flow3: Flow<T3>, flow4: Flow<T4>, flow5: Flow<T5>, flow6: Flow<T6>, flow7: Flow<T7>, transform: suspend (T1, T2, T3, T4, T5, T6, T7) -> R): Flow<R>
fun <T1, T2, T3, T4, T5, T6, T7, T8, R> combine(flow: Flow<T1>, flow2: Flow<T2>, flow3: Flow<T3>, flow4: Flow<T4>, flow5: Flow<T5>, flow6: Flow<T6>, flow7: Flow<T7>, flow8: Flow<T8>, transform: suspend (T1, T2, T3, T4, T5, T6, T7, T8) -> R): Flow<R>
fun <T1, T2, T3, T4, T5, T6, T7, T8, T9, R> combine(flow: Flow<T1>, flow2: Flow<T2>, flow3: Flow<T3>, flow4: Flow<T4>, flow5: Flow<T5>, flow6: Flow<T6>, flow7: Flow<T7>, flow8: Flow<T8>, flow9: Flow<T9>, transform: suspend (T1, T2, T3, T4, T5, T6, T7, T8, T9) -> R): Flow<R>
fun <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, R> combine(flow: Flow<T1>, flow2: Flow<T2>, flow3: Flow<T3>, flow4: Flow<T4>, flow5: Flow<T5>, flow6: Flow<T6>, flow7: Flow<T7>, flow8: Flow<T8>, flow9: Flow<T9>, flow10: Flow<T10>, transform: suspend (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10) -> R): Flow<R>
fun <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, R> combine(flow: Flow<T1>, flow2: Flow<T2>, flow3: Flow<T3>, flow4: Flow<T4>, flow5: Flow<T5>, flow6: Flow<T6>, flow7: Flow<T7>, flow8: Flow<T8>, flow9: Flow<T9>, flow10: Flow<T10>, flow11: Flow<T11>, transform: suspend (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11) -> R): Flow<R>
fun <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, R> combine(flow: Flow<T1>, flow2: Flow<T2>, flow3: Flow<T3>, flow4: Flow<T4>, flow5: Flow<T5>, flow6: Flow<T6>, flow7: Flow<T7>, flow8: Flow<T8>, flow9: Flow<T9>, flow10: Flow<T10>, flow11: Flow<T11>, flow12: Flow<T12>, transform: suspend (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12) -> R): Flow<R>

Returns a Flow whose values are generated with transform function by combining the most recently emitted values by each flow.

Link copied to clipboard
fun <T> concat(flows: Iterable<Flow<T>>): Flow<T>
fun <T> concat(flows: Sequence<Flow<T>>): Flow<T>
fun <T> concat(flow1: Flow<T>, flow2: Flow<T>): Flow<T>
fun <T> concat(flow1: Flow<T>, flow2: Flow<T>, vararg flows: Flow<T>): Flow<T>
fun <T> concat(flow1: Flow<T>, flow2: Flow<T>, flow3: Flow<T>): Flow<T>
fun <T> concat(flow1: Flow<T>, flow2: Flow<T>, flow3: Flow<T>, flow4: Flow<T>): Flow<T>
fun <T> concat(flow1: Flow<T>, flow2: Flow<T>, flow3: Flow<T>, flow4: Flow<T>, flow5: Flow<T>): Flow<T>

Creates an output Flow which sequentially emits all values from the first given Flow and then moves on to the next.

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
fun <T> defer(flowFactory: suspend () -> Flow<T>): Flow<T>

Creates a Flow that, on collection, calls a Flow factory to make a Flow for each new FlowCollector.

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> Event<T>.errorOrNull(): Throwable?

Returns the encapsulated error if this Event is an Event.Error, otherwise returns null.

Link copied to clipboard
inline fun <T> Event<T>.errorOrThrow(): Throwable

Returns the encapsulated error if this Event is an Event.Error. Otherwise, throws a NoSuchElementException.

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
inline fun <T, R> Event<T>.flatMap(transform: (T) -> Event<R>): Event<R>

Returns the result of applying transform to this Event's value if this is a Event.Value. Otherwise, returns itself.

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> flowFromNonSuspend(function: () -> T): Flow<T>

Creates a cold flow that produces a single value from the given function. It calls function for each new FlowCollector.

Link copied to clipboard
fun <T> flowFromSuspend(function: suspend () -> T): Flow<T>

Creates a cold flow that produces a single value from the given function. It calls function for each new FlowCollector.

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 interval(initialDelayMillis: Long, periodMillis: Long): Flow<Long>

Returns a Flow that emits a 0L after the initialDelayMillis and ever-increasing numbers after each periodMillis of time thereafter.

fun interval(initialDelay: Duration, period: Duration): Flow<Long>

Returns a Flow that emits a 0L after the initialDelay and ever-increasing numbers after each period of time thereafter.

Link copied to clipboard
inline fun <T, R> Event<T>.map(transform: (T) -> R): Event<R>

When this Event is a Event.Value, return a Event.Value containing transformed value using transform. Otherwise, returns itself.

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
inline fun neverFlow(): NeverFlow

Returns a NeverFlow that never emits any values to the FlowCollector and never completes.

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

Mirrors the one Flow in an Iterable of several Flows that first either emits a value or sends a termination event (error or complete event).

fun <T> race(flow1: Flow<T>, flow2: Flow<T>, vararg flows: Flow<T>): Flow<T>

Mirrors the one Flow in an array of several Flows that first either emits a value or sends a termination event (error or complete event).

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 range(start: Int, count: Int): Flow<Int>

Creates a Flow that emits a sequence of numbers within a specified range.

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
fun <T> timer(value: T, timeMillis: Long): Flow<T>

Creates a Flow that will wait for a specified time, before emitting the value.

fun <T> timer(value: T, duration: Duration): Flow<T>

Creates a Flow that will wait for a given duration, before emitting the value.

Link copied to clipboard
inline fun <T> Event<T>.valueOrDefault(defaultValue: T): T?

Returns the encapsulated value if this Event is a Event.Value, otherwise returns defaultValue.

Link copied to clipboard
inline fun <T> Event<T>.valueOrElse(defaultValue: (Throwable?) -> T): T

Returns the encapsulated value if this Event is a Event.Value, otherwise returns the result of calling defaultValue function.

Link copied to clipboard
inline fun <T> Event<T>.valueOrNull(): T?

Returns the encapsulated value if this Event is a Event.Value, otherwise returns null.

Link copied to clipboard
inline fun <T> Event<T>.valueOrThrow(): T

Returns the encapsulated value if this Event is a Event.Value. If this is Event.Error, throws the encapsulated error. Otherwise, throws a NoSuchElementException.

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.