Package kotlinx.coroutines.flow

Flow — asynchronous cold stream of elements.

Types

AbstractFlow
Link copied to clipboard
common
abstract class AbstractFlow<T> : Flow<T> , CancellableFlow<T>
Base class for stateful implementations of Flow.
Flow
Link copied to clipboard
common
interface Flow<out T>
An asynchronous data stream that sequentially emits values and completes normally or with an exception.
FlowCollector
Link copied to clipboard
common
interface FlowCollector<in T>
FlowCollector is used as an intermediate or a terminal collector of the flow and represents an entity that accepts values emitted by the Flow.
MutableSharedFlow
Link copied to clipboard
common
interface MutableSharedFlow<T> : SharedFlow<T> , FlowCollector<T>
A mutable SharedFlow that provides functions to emit values to the flow.
MutableStateFlow
Link copied to clipboard
common
interface MutableStateFlow<T> : StateFlow<T> , MutableSharedFlow<T>
A mutable StateFlow that provides a setter for value.
SharedFlow
Link copied to clipboard
common
interface SharedFlow<out T> : Flow<T>
A hotFlow that shares emitted values among all its collectors in a broadcast fashion, so that all collectors get all emitted values.
SharingCommand
Link copied to clipboard
common
enum SharingCommand : Enum<SharingCommand>
A command emitted by SharingStarted implementations to control the sharing coroutine in the shareIn and stateIn operators.
SharingStarted
Link copied to clipboard
common
fun fun interface SharingStarted
A strategy for starting and stopping the sharing coroutine in shareIn and stateIn operators.
StateFlow
Link copied to clipboard
common
interface StateFlow<out T> : SharedFlow<T>
A SharedFlow that represents a read-only state with a single updatable data value that emits updates to the value to its collectors.

Functions

asFlow
Link copied to clipboard
common
fun <T> Array<T>.asFlow(): Flow<T>
Creates a cold flow that produces values from the given array.
fun <T> () -> T.asFlow(): Flow<T>
Creates a cold flow that produces a single value from the given functional type.
fun IntArray.asFlow(): Flow<Int>
Creates a cold flow that produces values from the array.
fun LongArray.asFlow(): Flow<Long>
Creates a cold flow that produces values from the given array.
fun <T> Iterable<T>.asFlow(): Flow<T>
Creates a cold flow that produces values from the given iterable.
fun <T> Iterator<T>.asFlow(): Flow<T>
Creates a cold flow that produces values from the given iterator.
fun <T> suspend () -> T.asFlow(): Flow<T>
Creates a cold flow that produces a single value from the given functional type.
fun IntRange.asFlow(): Flow<Int>
Creates a flow that produces values from the range.
fun LongRange.asFlow(): Flow<Long>
Creates a flow that produces values from the range.
fun <T> Sequence<T>.asFlow(): Flow<T>
Creates a cold flow that produces values from the given sequence.
fun <T> BroadcastChannel<T>.asFlow(): Flow<T>
Represents the given broadcast channel as a hot flow.
asSharedFlow
Link copied to clipboard
common
fun <T> MutableSharedFlow<T>.asSharedFlow(): SharedFlow<T>
Represents this mutable shared flow as a read-only shared flow.
asStateFlow
Link copied to clipboard
common
fun <T> MutableStateFlow<T>.asStateFlow(): StateFlow<T>
Represents this mutable state flow as a read-only state flow.
broadcastIn
Link copied to clipboard
common
fun <T> Flow<T>.broadcastIn(scope: CoroutineScope, start: CoroutineStart = CoroutineStart.LAZY): BroadcastChannel<T>

Deprecated

This API is deprecated.
buffer
Link copied to clipboard
common
fun <T> Flow<T>.buffer(capacity: Int = BUFFERED): Flow<T>
fun <T> Flow<T>.buffer(capacity: Int = BUFFERED, onBufferOverflow: BufferOverflow = BufferOverflow.SUSPEND): Flow<T>
Buffers flow emissions via channel of a specified capacity and runs collector in a separate coroutine.
cache
Link copied to clipboard
common
fun <T> Flow<T>.cache(): Flow<T>
callbackFlow
Link copied to clipboard
common
fun <T> callbackFlow(block: suspend ProducerScope<T>.() -> Unit): Flow<T>
Creates an instance of a coldFlow with elements that are sent to a SendChannel provided to the builder's block of code via ProducerScope.
cancel
Link copied to clipboard
common
fun FlowCollector<*>.cancel(cause: CancellationException? = null)
cancellable
Link copied to clipboard
common
fun <T> Flow<T>.cancellable(): Flow<T>
Returns a flow which checks cancellation status on each emission and throws the corresponding cancellation cause if flow collector was cancelled.
fun <T> SharedFlow<T>.cancellable(): Flow<T>
Applying cancellable to a SharedFlow has no effect.
catch
Link copied to clipboard
common
fun <T> Flow<T>.catch(action: suspend FlowCollector<T>.(cause: Throwable) -> Unit): Flow<T>
Catches exceptions in the flow completion and calls a specified action with the caught exception.
inline fun <T> SharedFlow<T>.catch(noinline action: suspend FlowCollector<T>.(cause: Throwable) -> Unit): Flow<T>
channelFlow
Link copied to clipboard
common
fun <T> channelFlow(block: suspend ProducerScope<T>.() -> Unit): Flow<T>
Creates an instance of a coldFlow with elements that are sent to a SendChannel provided to the builder's block of code via ProducerScope.
collect
Link copied to clipboard
common
suspend fun Flow<*>.collect()
Terminal flow operator that collects the given flow but ignores all emitted values.
inline suspend fun <T> Flow<T>.collect(crossinline action: suspend (T) -> Unit)
Terminal flow operator that collects the given flow with a provided action.
collectIndexed
Link copied to clipboard
common
inline suspend fun <T> Flow<T>.collectIndexed(crossinline action: suspend (index: Int, T) -> Unit)
Terminal flow operator that collects the given flow with a provided action that takes the index of an element (zero-based) and the element.
collectLatest
Link copied to clipboard
common
suspend fun <T> Flow<T>.collectLatest(action: suspend (T) -> Unit)
Terminal flow operator that collects the given flow with a provided action.
combine
Link copied to clipboard
common
inline fun <T, R> combine(vararg flows: Flow<T>, crossinline transform: suspend (Array<T>) -> R): Flow<R>
Returns a Flow whose values are generated with transform function by combining the most recently emitted values by each flow.
inline fun <T, R> combine(flows: Iterable<Flow<T>>, crossinline transform: suspend (Array<T>) -> R): Flow<R>
Returns a Flow whose values are generated with transform function by combining the most recently emitted values by each flow.
@JvmName(name = flowCombine)
fun <T1, T2, R> Flow<T1>.combine(flow: Flow<T2>, transform: suspend (T1, T2) -> R): Flow<R>
Returns a Flow whose values are generated with transform function by combining the most recently emitted values by each flow.
fun <T1, T2, R> combine(flow: Flow<T1>, flow2: Flow<T2>, transform: suspend (T1, T2) -> R): Flow<R>
Returns a Flow whose values are generated with transform function by combining the most recently emitted values by each flow.
fun <T1, T2, T3, R> combine(flow: Flow<T1>, flow2: Flow<T2>, flow3: Flow<T3>, transform: suspend (T1, T2, T3) -> R): Flow<R>
Returns a Flow whose values are generated with transform function by combining the most recently emitted values by each flow.
fun <T1, T2, T3, T4, R> combine(flow: Flow<T1>, flow2: Flow<T2>, flow3: Flow<T3>, flow4: Flow<T4>, transform: suspend (T1, T2, T3, T4) -> R): Flow<R>
Returns a Flow whose values are generated with transform function by combining the most recently emitted values by each flow.
fun <T1, T2, T3, T4, T5, R> combine(flow: Flow<T1>, flow2: Flow<T2>, flow3: Flow<T3>, flow4: Flow<T4>, flow5: Flow<T5>, transform: suspend (T1, T2, T3, T4, T5) -> R): Flow<R>
Returns a Flow whose values are generated with transform function by combining the most recently emitted values by each flow.
combineLatest
Link copied to clipboard
common
fun <T1, T2, R> Flow<T1>.combineLatest(other: Flow<T2>, transform: suspend (T1, T2) -> R): Flow<R>
fun <T1, T2, T3, R> Flow<T1>.combineLatest(other: Flow<T2>, other2: Flow<T3>, transform: suspend (T1, T2, T3) -> R): Flow<R>
fun <T1, T2, T3, T4, R> Flow<T1>.combineLatest(other: Flow<T2>, other2: Flow<T3>, other3: Flow<T4>, transform: suspend (T1, T2, T3, T4) -> R): Flow<R>
fun <T1, T2, T3, T4, T5, R> Flow<T1>.combineLatest(other: Flow<T2>, other2: Flow<T3>, other3: Flow<T4>, other4: Flow<T5>, transform: suspend (T1, T2, T3, T4, T5) -> R): Flow<R>
combineTransform
Link copied to clipboard
common
inline fun <T, R> combineTransform(vararg flows: Flow<T>, crossinline transform: suspend FlowCollector<R>.(Array<T>) -> Unit): Flow<R>
Returns a Flow whose values are generated by transform function that process the most recently emitted values by each flow.
inline fun <T, R> combineTransform(flows: Iterable<Flow<T>>, crossinline transform: suspend FlowCollector<R>.(Array<T>) -> Unit): Flow<R>
Returns a Flow whose values are generated by transform function that process the most recently emitted values by each flow.
@JvmName(name = flowCombineTransform)
fun <T1, T2, R> Flow<T1>.combineTransform(flow: Flow<T2>, transform: suspend FlowCollector<R>.(T1, T2) -> Unit): Flow<R>
Returns a Flow whose values are generated by transform function that process the most recently emitted values by each flow.
fun <T1, T2, R> combineTransform(flow: Flow<T1>, flow2: Flow<T2>, transform: suspend FlowCollector<R>.(T1, T2) -> Unit): Flow<R>
Returns a Flow whose values are generated by transform function that process the most recently emitted values by each flow.
fun <T1, T2, T3, R> combineTransform(flow: Flow<T1>, flow2: Flow<T2>, flow3: Flow<T3>, transform: suspend FlowCollector<R>.(T1, T2, T3) -> Unit): Flow<R>
Returns a Flow whose values are generated by transform function that process the most recently emitted values by each flow.
fun <T1, T2, T3, T4, R> combineTransform(flow: Flow<T1>, flow2: Flow<T2>, flow3: Flow<T3>, flow4: Flow<T4>, transform: suspend FlowCollector<R>.(T1, T2, T3, T4) -> Unit): Flow<R>
Returns a Flow whose values are generated by transform function that process the most recently emitted values by each flow.
fun <T1, T2, T3, T4, T5, R> combineTransform(flow: Flow<T1>, flow2: Flow<T2>, flow3: Flow<T3>, flow4: Flow<T4>, flow5: Flow<T5>, transform: suspend FlowCollector<R>.(T1, T2, T3, T4, T5) -> Unit): Flow<R>
Returns a Flow whose values are generated by transform function that process the most recently emitted values by each flow.
conflate
Link copied to clipboard
common
fun <T> Flow<T>.conflate(): Flow<T>
Conflates flow emissions via conflated channel and runs collector in a separate coroutine.
fun <T> StateFlow<T>.conflate(): Flow<T>
Applying conflate to StateFlow has no effect.
consumeAsFlow
Link copied to clipboard
common
fun <T> ReceiveChannel<T>.consumeAsFlow(): Flow<T>
Represents the given receive channel as a hot flow and consumes the channel on the first collection from this flow.
count
Link copied to clipboard
common
suspend fun <T> Flow<T>.count(): Int
Returns the number of elements in this flow.
inline suspend fun <T> SharedFlow<T>.count(): Int
suspend fun <T> Flow<T>.count(predicate: suspend (T) -> Boolean): Int
Returns the number of elements matching the given predicate.
debounce
Link copied to clipboard
common
fun <T> Flow<T>.debounce(timeoutMillis: (T) -> Long): Flow<T>
Returns a flow that mirrors the original flow, but filters out values that are followed by the newer values within the given timeout.
@JvmName(name = debounceDuration)
fun <T> Flow<T>.debounce(timeout: (T) -> Duration): Flow<T>
Returns a flow that mirrors the original flow, but filters out values that are followed by the newer values within the given timeout.
fun <T> Flow<T>.debounce(timeoutMillis: Long): Flow<T>
Returns a flow that mirrors the original flow, but filters out values that are followed by the newer values within the given timeout.
fun <T> Flow<T>.debounce(timeout: Duration): Flow<T>
Returns a flow that mirrors the original flow, but filters out values that are followed by the newer values within the given timeout.
distinctUntilChanged
Link copied to clipboard
common
fun <T> Flow<T>.distinctUntilChanged(): Flow<T>
Returns flow where all subsequent repetitions of the same value are filtered out.
fun <T> StateFlow<T>.distinctUntilChanged(): Flow<T>
Applying distinctUntilChanged to StateFlow has no effect.
fun <T> Flow<T>.distinctUntilChanged(areEquivalent: (T, T) -> Boolean): Flow<T>
Returns flow where all subsequent repetitions of the same value are filtered out, when compared with each other via the provided areEquivalent function.
distinctUntilChangedBy
Link copied to clipboard
common
fun <T, K> Flow<T>.distinctUntilChangedBy(keySelector: (T) -> K): Flow<T>
Returns flow where all subsequent repetitions of the same key are filtered out, where key is extracted with keySelector function.
drop
Link copied to clipboard
common
fun <T> Flow<T>.drop(count: Int): Flow<T>
Returns a flow that ignores first count elements.
dropWhile
Link copied to clipboard
common
fun <T> Flow<T>.dropWhile(predicate: suspend (T) -> Boolean): Flow<T>
Returns a flow containing all elements except first elements that satisfy the given predicate.
emitAll
Link copied to clipboard
common
suspend fun <T> FlowCollector<T>.emitAll(channel: ReceiveChannel<T>)
Emits all elements from the given channel to this flow collector and cancels (consumes) the channel afterwards.
suspend fun <T> FlowCollector<T>.emitAll(flow: Flow<T>)
Collects all the values from the given flow and emits them to the collector.
emptyFlow
Link copied to clipboard
common
fun <T> emptyFlow(): Flow<T>
Returns an empty flow.
filter
Link copied to clipboard
common
inline fun <T> Flow<T>.filter(crossinline predicate: suspend (T) -> Boolean): Flow<T>
Returns a flow containing only values of the original flow that match the given predicate.
filterIsInstance
Link copied to clipboard
common
inline fun <R> Flow<*>.filterIsInstance(): Flow<R>
Returns a flow containing only values that are instances of specified type R.
filterNot
Link copied to clipboard
common
inline fun <T> Flow<T>.filterNot(crossinline predicate: suspend (T) -> Boolean): Flow<T>
Returns a flow containing only values of the original flow that do not match the given predicate.
filterNotNull
Link copied to clipboard
common
fun <T : Any> Flow<T?>.filterNotNull(): Flow<T>
Returns a flow containing only values of the original flow that are not null.
first
Link copied to clipboard
common
suspend fun <T> Flow<T>.first(): T
The terminal operator that returns the first element emitted by the flow and then cancels flow's collection.
suspend fun <T> Flow<T>.first(predicate: suspend (T) -> Boolean): T
The terminal operator that returns the first element emitted by the flow matching the given predicate and then cancels flow's collection.
firstOrNull
Link copied to clipboard
common
suspend fun <T> Flow<T>.firstOrNull(): T?
The terminal operator that returns the first element emitted by the flow and then cancels flow's collection.
suspend fun <T> Flow<T>.firstOrNull(predicate: suspend (T) -> Boolean): T?
The terminal operator that returns the first element emitted by the flow matching the given predicate and then cancels flow's collection.
flatMapConcat
Link copied to clipboard
common
fun <T, R> Flow<T>.flatMapConcat(transform: suspend (T) -> Flow<R>): Flow<R>
Transforms elements emitted by the original flow by applying transform, that returns another flow, and then concatenating and flattening these flows.
flatMapLatest
Link copied to clipboard
common
inline fun <T, R> Flow<T>.flatMapLatest(crossinline transform: suspend (T) -> Flow<R>): Flow<R>
Returns a flow that switches to a new flow produced by transform function every time the original flow emits a value.
flatMapMerge
Link copied to clipboard
common
fun <T, R> Flow<T>.flatMapMerge(concurrency: Int = DEFAULT_CONCURRENCY, transform: suspend (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.
flattenConcat
Link copied to clipboard
common
fun <T> Flow<Flow<T>>.flattenConcat(): Flow<T>
Flattens the given flow of flows into a single flow in a sequentially manner, without interleaving nested flows.
flattenMerge
Link copied to clipboard
common
fun <T> Flow<Flow<T>>.flattenMerge(concurrency: Int = DEFAULT_CONCURRENCY): Flow<T>
Flattens the given flow of flows into a single flow with a concurrency limit on the number of concurrently collected flows.
flow
Link copied to clipboard
common
fun <T> flow(block: suspend FlowCollector<T>.() -> Unit): Flow<T>
Creates a cold flow from the given suspendable block.
flowOf
Link copied to clipboard
common
fun <T> flowOf(value: T): Flow<T>
Creates a flow that produces the given value.
fun <T> flowOf(vararg elements: T): Flow<T>
Creates a flow that produces values from the specified vararg-arguments.
flowOn
Link copied to clipboard
common
fun <T> Flow<T>.flowOn(context: CoroutineContext): Flow<T>
Changes the context where this flow is executed to the given context.
fun <T> SharedFlow<T>.flowOn(context: CoroutineContext): Flow<T>
Applying flowOn to SharedFlow has no effect.
fold
Link copied to clipboard
common
inline suspend fun <T, R> Flow<T>.fold(initial: R, crossinline operation: suspend (R, T) -> R): R
Accumulates value starting with initial value and applying operation current accumulator value and each element
getAndUpdate
Link copied to clipboard
common
inline fun <T> MutableStateFlow<T>.getAndUpdate(function: (T) -> T): T
Updates the MutableStateFlow.value atomically using the specified function of its value, and returns its prior value.
last
Link copied to clipboard
common
suspend fun <T> Flow<T>.last(): T
The terminal operator that returns the last element emitted by the flow.
lastOrNull
Link copied to clipboard
common
suspend fun <T> Flow<T>.lastOrNull(): T?
The terminal operator that returns the last element emitted by the flow or null if the flow was empty.
launchIn
Link copied to clipboard
common
fun <T> Flow<T>.launchIn(scope: CoroutineScope): Job
Terminal flow operator that launches the collection of the given flow in the scope.
map
Link copied to clipboard
common
inline fun <T, R> Flow<T>.map(crossinline transform: suspend (T) -> R): Flow<R>
Returns a flow containing the results of applying the given transform function to each value of the original flow.
mapLatest
Link copied to clipboard
common
fun <T, R> Flow<T>.mapLatest(transform: suspend (T) -> R): Flow<R>
Returns a flow that emits elements from the original flow transformed by transform function.
mapNotNull
Link copied to clipboard
common
inline fun <T, R : Any> Flow<T>.mapNotNull(crossinline transform: suspend (T) -> R?): Flow<R>
Returns a flow that contains only non-null results of applying the given transform function to each value of the original flow.
merge
Link copied to clipboard
common
fun <T> Iterable<Flow<T>>.merge(): Flow<T>
Merges the given flows into a single flow without preserving an order of elements.
fun <T> merge(vararg flows: Flow<T>): Flow<T>
Merges the given flows into a single flow without preserving an order of elements.
MutableSharedFlow
Link copied to clipboard
common
fun <T> MutableSharedFlow(replay: Int = 0, extraBufferCapacity: Int = 0, onBufferOverflow: BufferOverflow = BufferOverflow.SUSPEND): MutableSharedFlow<T>
Creates a MutableSharedFlow with the given configuration parameters.
MutableStateFlow
Link copied to clipboard
common
fun <T> MutableStateFlow(value: T): MutableStateFlow<T>
Creates a MutableStateFlow with the given initial value.
onCompletion
Link copied to clipboard
common
fun <T> Flow<T>.onCompletion(action: suspend FlowCollector<T>.(cause: Throwable?) -> Unit): Flow<T>
Returns a flow that invokes the given actionafter the flow is completed or cancelled, passing the cancellation exception or failure as cause parameter of action.
onEach
Link copied to clipboard
common
fun <T> Flow<T>.onEach(action: suspend (T) -> Unit): Flow<T>
Returns a flow that invokes the given actionbefore each value of the upstream flow is emitted downstream.
onEmpty
Link copied to clipboard
common
fun <T> Flow<T>.onEmpty(action: suspend FlowCollector<T>.() -> Unit): Flow<T>
Invokes the given action when this flow completes without emitting any elements.
onStart
Link copied to clipboard
common
fun <T> Flow<T>.onStart(action: suspend FlowCollector<T>.() -> Unit): Flow<T>
Returns a flow that invokes the given actionbefore this flow starts to be collected.
onSubscription
Link copied to clipboard
common
fun <T> SharedFlow<T>.onSubscription(action: suspend FlowCollector<T>.() -> Unit): SharedFlow<T>
Returns a flow that invokes the given actionafter this shared flow starts to be collected (after the subscription is registered).
produceIn
Link copied to clipboard
common
fun <T> Flow<T>.produceIn(scope: CoroutineScope): ReceiveChannel<T>
Creates a produce coroutine that collects the given flow.
publish
Link copied to clipboard
common
fun <T> Flow<T>.publish(): Flow<T>
fun <T> Flow<T>.publish(bufferSize: Int): Flow<T>
receiveAsFlow
Link copied to clipboard
common
fun <T> ReceiveChannel<T>.receiveAsFlow(): Flow<T>
Represents the given receive channel as a hot flow and receives from the channel in fan-out fashion every time this flow is collected.
reduce
Link copied to clipboard
common
suspend fun <S, T : S> Flow<T>.reduce(operation: suspend (S, T) -> S): S
Accumulates value starting with the first element and applying operation to current accumulator value and each element.
replay
Link copied to clipboard
common
fun <T> Flow<T>.replay(): Flow<T>
fun <T> Flow<T>.replay(bufferSize: Int): Flow<T>
retry
Link copied to clipboard
common
fun <T> Flow<T>.retry(retries: Int = Int.MAX_VALUE, predicate: (Throwable) -> Boolean = { true }): Flow<T>
inline fun <T> SharedFlow<T>.retry(retries: Long = Long.MAX_VALUE, noinline predicate: suspend (cause: Throwable) -> Boolean = { true }): Flow<T>
fun <T> Flow<T>.retry(retries: Long = Long.MAX_VALUE, predicate: suspend (cause: Throwable) -> Boolean = { true }): Flow<T>
Retries collection of the given flow up to retries times when an exception that matches the given predicate occurs in the upstream flow.
retryWhen
Link copied to clipboard
common
fun <T> Flow<T>.retryWhen(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.
inline fun <T> SharedFlow<T>.retryWhen(noinline predicate: suspend FlowCollector<T>.(cause: Throwable, attempt: Long) -> Boolean): Flow<T>
runningFold
Link copied to clipboard
common
fun <T, R> Flow<T>.runningFold(initial: R, operation: suspend (R, T) -> R): Flow<R>
Folds the given flow with operation, emitting every intermediate result, including initial value.
runningReduce
Link copied to clipboard
common
fun <T> Flow<T>.runningReduce(operation: suspend (T, T) -> T): Flow<T>
Reduces the given flow with operation, emitting every intermediate result, including initial value.
sample
Link copied to clipboard
common
fun <T> Flow<T>.sample(periodMillis: Long): Flow<T>
Returns a flow that emits only the latest value emitted by the original flow during the given sampling period.
fun <T> Flow<T>.sample(period: Duration): Flow<T>
Returns a flow that emits only the latest value emitted by the original flow during the given sampling period.
scan
Link copied to clipboard
common
fun <T, R> Flow<T>.scan(initial: R, operation: suspend (R, T) -> R): Flow<R>
Folds the given flow with operation, emitting every intermediate result, including initial value.
scanReduce
Link copied to clipboard
common
fun <T> Flow<T>.scanReduce(operation: suspend (T, T) -> T): Flow<T>
shareIn
Link copied to clipboard
common
fun <T> Flow<T>.shareIn(scope: CoroutineScope, started: SharingStarted, replay: Int = 0): SharedFlow<T>
Converts a coldFlow into a hotSharedFlow that is started in the given coroutine scope, sharing emissions from a single running instance of the upstream flow with multiple downstream subscribers, and replaying a specified number of replay values to new subscribers.
single
Link copied to clipboard
common
suspend fun <T> Flow<T>.single(): T
The terminal operator that awaits for one and only one value to be emitted.
singleOrNull
Link copied to clipboard
common
suspend fun <T> Flow<T>.singleOrNull(): T?
The terminal operator that awaits for one and only one value to be emitted.
stateIn
Link copied to clipboard
common
suspend fun <T> Flow<T>.stateIn(scope: CoroutineScope): StateFlow<T>
Starts the upstream flow in a given scope, suspends until the first value is emitted, and returns a hotStateFlow of future emissions, sharing the most recently emitted value from this running instance of the upstream flow with multiple downstream subscribers.
fun <T> Flow<T>.stateIn(scope: CoroutineScope, started: SharingStarted, initialValue: T): StateFlow<T>
Converts a coldFlow into a hotStateFlow that is started in the given coroutine scope, sharing the most recently emitted value from a single running instance of the upstream flow with multiple downstream subscribers.
switchMap
Link copied to clipboard
common
fun <T, R> Flow<T>.switchMap(transform: suspend (T) -> Flow<R>): Flow<R>
take
Link copied to clipboard
common
fun <T> Flow<T>.take(count: Int): Flow<T>
Returns a flow that contains first count elements.
takeWhile
Link copied to clipboard
common
fun <T> Flow<T>.takeWhile(predicate: suspend (T) -> Boolean): Flow<T>
Returns a flow that contains first elements satisfying the given predicate.
toCollection
Link copied to clipboard
common
suspend fun <T, C : MutableCollection<in T>> Flow<T>.toCollection(destination: C): C
Collects given flow into a destination
toList
Link copied to clipboard
common
inline suspend fun <T> SharedFlow<T>.toList(): List<T>
suspend fun <T> Flow<T>.toList(destination: MutableList<T> = ArrayList()): List<T>
Collects given flow into a destination
toSet
Link copied to clipboard
common
inline suspend fun <T> SharedFlow<T>.toSet(): Set<T>
suspend fun <T> Flow<T>.toSet(destination: MutableSet<T> = LinkedHashSet()): Set<T>
Collects given flow into a destination
transform
Link copied to clipboard
common
inline fun <T, R> Flow<T>.transform(crossinline transform: suspend FlowCollector<R>.(T) -> Unit): Flow<R>
Applies transform function to each value of the given flow.
transformLatest
Link copied to clipboard
common
fun <T, R> Flow<T>.transformLatest(transform: suspend FlowCollector<R>.(T) -> Unit): Flow<R>
Returns a flow that produces element by transform function every time the original flow emits a value.
transformWhile
Link copied to clipboard
common
fun <T, R> Flow<T>.transformWhile(transform: suspend FlowCollector<R>.(T) -> Boolean): Flow<R>
Applies transform function to each value of the given flow while this function returns true.
update
Link copied to clipboard
common
inline fun <T> MutableStateFlow<T>.update(function: (T) -> T)
Updates the MutableStateFlow.value atomically using the specified function of its value.
updateAndGet
Link copied to clipboard
common
inline fun <T> MutableStateFlow<T>.updateAndGet(function: (T) -> T): T
Updates the MutableStateFlow.value atomically using the specified function of its value, and returns the new value.
WhileSubscribed
Link copied to clipboard
common
fun SharingStarted.Companion.WhileSubscribed(stopTimeout: Duration = Duration.ZERO, replayExpiration: Duration = Duration.INFINITE): SharingStarted
Sharing is started when the first subscriber appears, immediately stops when the last subscriber disappears (by default), keeping the replay cache forever (by default).
withIndex
Link copied to clipboard
common
fun <T> Flow<T>.withIndex(): Flow<IndexedValue<T>>
Returns a flow that wraps each element into IndexedValue, containing value and its index (starting from zero).
zip
Link copied to clipboard
common
fun <T1, T2, R> Flow<T1>.zip(other: Flow<T2>, transform: suspend (T1, T2) -> R): Flow<R>
Zips values from the current flow (this) with other flow using provided transform function applied to each pair of values.

Properties

coroutineContext
Link copied to clipboard
common
val FlowCollector<*>.coroutineContext: CoroutineContext
DEFAULT_CONCURRENCY
Link copied to clipboard
common
val DEFAULT_CONCURRENCY: Int
Default concurrency limit that is used by flattenMerge and flatMapMerge operators.
DEFAULT_CONCURRENCY_PROPERTY_NAME
Link copied to clipboard
common
const val DEFAULT_CONCURRENCY_PROPERTY_NAME: String
Name of the property that defines the value of DEFAULT_CONCURRENCY.
isActive
Link copied to clipboard
common
val FlowCollector<*>.isActive: Boolean