Skip to content

Commit

Permalink
Remove experimental status from Flow API (#1963)
Browse files Browse the repository at this point in the history
* Remove experimental annotation from Flow terminal and Channel operators
* Remove experimental annotation from Flow count* and reduce* operators
* Remove experimental annotation from Flow operations, including buffer and flowOn
* Remove experimental annotation from combine and zip
  • Loading branch information
qwwdfsad authored Apr 28, 2020
1 parent 515e86a commit 5b00e48
Show file tree
Hide file tree
Showing 11 changed files with 0 additions and 42 deletions.
3 changes: 0 additions & 3 deletions kotlinx-coroutines-core/common/src/flow/Channels.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import kotlinx.coroutines.flow.internal.unsafeFlow as flow
* This function provides a more efficient shorthand for `channel.consumeEach { value -> emit(value) }`.
* See [consumeEach][ReceiveChannel.consumeEach].
*/
@ExperimentalCoroutinesApi // since version 1.3.0
public suspend fun <T> FlowCollector<T>.emitAll(channel: ReceiveChannel<T>): Unit =
emitAllImpl(channel, consume = true)

Expand Down Expand Up @@ -84,7 +83,6 @@ private suspend fun <T> FlowCollector<T>.emitAllImpl(channel: ReceiveChannel<T>,
* In particular, [produceIn] returns the original channel.
* Calls to [flowOn] have generally no effect, unless [buffer] is used to explicitly request buffering.
*/
@ExperimentalCoroutinesApi // since version 1.4.0
public fun <T> ReceiveChannel<T>.receiveAsFlow(): Flow<T> = ChannelAsFlow(this, consume = false)

/**
Expand All @@ -106,7 +104,6 @@ public fun <T> ReceiveChannel<T>.receiveAsFlow(): Flow<T> = ChannelAsFlow(this,
* In particular, [produceIn] returns the original channel (but throws [IllegalStateException] on repeated calls).
* Calls to [flowOn] have generally no effect, unless [buffer] is used to explicitly request buffering.
*/
@ExperimentalCoroutinesApi // since version 1.3.0
public fun <T> ReceiveChannel<T>.consumeAsFlow(): Flow<T> = ChannelAsFlow(this, consume = true)

/**
Expand Down
3 changes: 0 additions & 3 deletions kotlinx-coroutines-core/common/src/flow/operators/Context.kt
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ import kotlin.jvm.*
* [RENDEZVOUS][Channel.RENDEZVOUS], [UNLIMITED][Channel.UNLIMITED] or a non-negative value indicating
* an explicitly requested size.
*/
@ExperimentalCoroutinesApi
public fun <T> Flow<T>.buffer(capacity: Int = BUFFERED): Flow<T> {
require(capacity >= 0 || capacity == BUFFERED || capacity == CONFLATED) {
"Buffer size should be non-negative, BUFFERED, or CONFLATED, but was $capacity"
Expand Down Expand Up @@ -147,7 +146,6 @@ public fun <T> Flow<T>.buffer(capacity: Int = BUFFERED): Flow<T> {
* always fused so that only one properly configured channel is used for execution.
* **Conflation takes precedence over `buffer()` calls with any other capacity.**
*/
@ExperimentalCoroutinesApi
public fun <T> Flow<T>.conflate(): Flow<T> = buffer(CONFLATED)

/**
Expand Down Expand Up @@ -194,7 +192,6 @@ public fun <T> Flow<T>.conflate(): Flow<T> = buffer(CONFLATED)
*
* @throws [IllegalArgumentException] if provided context contains [Job] instance.
*/
@ExperimentalCoroutinesApi
public fun <T> Flow<T>.flowOn(context: CoroutineContext): Flow<T> {
checkFlowContext(context)
return when {
Expand Down
3 changes: 0 additions & 3 deletions kotlinx-coroutines-core/common/src/flow/operators/Distinct.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,19 @@ import kotlinx.coroutines.flow.internal.unsafeFlow as flow
/**
* Returns flow where all subsequent repetitions of the same value are filtered out.
*/
@ExperimentalCoroutinesApi
public fun <T> Flow<T>.distinctUntilChanged(): Flow<T> = distinctUntilChangedBy { it }

/**
* Returns flow where all subsequent repetitions of the same value are filtered out, when compared
* with each other via the provided [areEquivalent] function.
*/
@FlowPreview
public fun <T> Flow<T>.distinctUntilChanged(areEquivalent: (old: T, new: T) -> Boolean): Flow<T> =
distinctUntilChangedBy(keySelector = { it }, areEquivalent = areEquivalent)

/**
* Returns flow where all subsequent repetitions of the same key are filtered out, where
* key is extracted with [keySelector] function.
*/
@FlowPreview
public fun <T, K> Flow<T>.distinctUntilChangedBy(keySelector: (T) -> K): Flow<T> =
distinctUntilChangedBy(keySelector = keySelector, areEquivalent = { old, new -> old == new })

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import kotlin.jvm.*
* }
* ```
*/
@ExperimentalCoroutinesApi
public inline fun <T, R> Flow<T>.transform(
@BuilderInference crossinline transform: suspend FlowCollector<R>.(value: T) -> Unit
): Flow<R> = flow { // Note: safe flow is used here, because collector is exposed to transform on each operation
Expand Down
3 changes: 0 additions & 3 deletions kotlinx-coroutines-core/common/src/flow/operators/Errors.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ import kotlinx.coroutines.flow.internal.unsafeFlow as flow
* retry an original flow use [retryWhen] operator that can retry the flow multiple times without
* introducing ever-growing stack of suspending calls.
*/
@ExperimentalCoroutinesApi // tentatively stable in 1.3.0
public fun <T> Flow<T>.catch(action: suspend FlowCollector<T>.(cause: Throwable) -> Unit): Flow<T> =
flow {
val exception = catchImpl(this)
Expand Down Expand Up @@ -117,7 +116,6 @@ public fun <T> Flow<T>.onErrorCollect(
*
* @throws IllegalArgumentException when [retries] is not positive.
*/
@ExperimentalCoroutinesApi // tentatively stable in 1.3.0
public fun <T> Flow<T>.retry(
retries: Long = Long.MAX_VALUE,
predicate: suspend (cause: Throwable) -> Boolean = { true }
Expand Down Expand Up @@ -169,7 +167,6 @@ public fun <T> Flow<T>.retry(
*
* See [catch] for more details.
*/
@ExperimentalCoroutinesApi // tentatively stable in 1.3.0
public fun <T> Flow<T>.retryWhen(predicate: suspend FlowCollector<T>.(cause: Throwable, attempt: Long) -> Boolean): Flow<T> =
flow {
var attempt = 0L
Expand Down
5 changes: 0 additions & 5 deletions kotlinx-coroutines-core/common/src/flow/operators/Limit.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

package kotlinx.coroutines.flow

import kotlinx.coroutines.*
import kotlinx.coroutines.flow.internal.*
import kotlin.jvm.*
import kotlinx.coroutines.flow.internal.unsafeFlow as flow
Expand All @@ -16,7 +15,6 @@ import kotlinx.coroutines.flow.internal.unsafeFlow as flow
* Returns a flow that ignores first [count] elements.
* Throws [IllegalArgumentException] if [count] is negative.
*/
@ExperimentalCoroutinesApi
public fun <T> Flow<T>.drop(count: Int): Flow<T> {
require(count >= 0) { "Drop count should be non-negative, but had $count" }
return flow {
Expand All @@ -30,7 +28,6 @@ public fun <T> Flow<T>.drop(count: Int): Flow<T> {
/**
* Returns a flow containing all elements except first elements that satisfy the given predicate.
*/
@ExperimentalCoroutinesApi
public fun <T> Flow<T>.dropWhile(predicate: suspend (T) -> Boolean): Flow<T> = flow {
var matched = false
collect { value ->
Expand All @@ -48,7 +45,6 @@ public fun <T> Flow<T>.dropWhile(predicate: suspend (T) -> Boolean): Flow<T> = f
* When [count] elements are consumed, the original flow is cancelled.
* Throws [IllegalArgumentException] if [count] is not positive.
*/
@ExperimentalCoroutinesApi
public fun <T> Flow<T>.take(count: Int): Flow<T> {
require(count > 0) { "Requested element count $count should be positive" }
return flow {
Expand All @@ -75,7 +71,6 @@ private suspend fun <T> FlowCollector<T>.emitAbort(value: T) {
/**
* Returns a flow that contains first elements satisfying the given [predicate].
*/
@ExperimentalCoroutinesApi
public fun <T> Flow<T>.takeWhile(predicate: suspend (T) -> Boolean): Flow<T> = flow {
try {
collect { value ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ public inline fun <T, R: Any> Flow<T>.mapNotNull(crossinline transform: suspend
/**
* Returns a flow that wraps each element into [IndexedValue], containing value and its index (starting from zero).
*/
@ExperimentalCoroutinesApi
public fun <T> Flow<T>.withIndex(): Flow<IndexedValue<T>> = flow {
var index = 0
collect { value ->
Expand Down
15 changes: 0 additions & 15 deletions kotlinx-coroutines-core/common/src/flow/operators/Zip.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import kotlinx.coroutines.flow.internal.unsafeFlow as flow
* This function is a shorthand for `flow.combineTransform(flow2) { a, b -> emit(transform(a, b)) }
*/
@JvmName("flowCombine")
@ExperimentalCoroutinesApi
public fun <T1, T2, R> Flow<T1>.combine(flow: Flow<T2>, transform: suspend (a: T1, b: T2) -> R): Flow<R> = flow {
combineTransformInternal(this@combine, flow) { a, b ->
emit(transform(a, b))
Expand All @@ -52,7 +51,6 @@ public fun <T1, T2, R> Flow<T1>.combine(flow: Flow<T2>, transform: suspend (a: T
*
* This function is a shorthand for `combineTransform(flow, flow2) { a, b -> emit(transform(a, b)) }
*/
@ExperimentalCoroutinesApi
public fun <T1, T2, R> combine(flow: Flow<T1>, flow2: Flow<T2>, transform: suspend (a: T1, b: T2) -> R): Flow<R> =
flow.combine(flow2, transform)

Expand All @@ -74,7 +72,6 @@ public fun <T1, T2, R> combine(flow: Flow<T1>, flow2: Flow<T2>, transform: suspe
* ```
*/
@JvmName("flowCombineTransform")
@ExperimentalCoroutinesApi
public fun <T1, T2, R> Flow<T1>.combineTransform(
flow: Flow<T2>,
@BuilderInference transform: suspend FlowCollector<R>.(a: T1, b: T2) -> Unit
Expand All @@ -101,7 +98,6 @@ public fun <T1, T2, R> Flow<T1>.combineTransform(
* }
* ```
*/
@ExperimentalCoroutinesApi
public fun <T1, T2, R> combineTransform(
flow: Flow<T1>,
flow2: Flow<T2>,
Expand All @@ -117,7 +113,6 @@ public fun <T1, T2, R> combineTransform(
* Returns a [Flow] whose values are generated with [transform] function by combining
* the most recently emitted values by each flow.
*/
@ExperimentalCoroutinesApi
public inline fun <T1, T2, T3, R> combine(
flow: Flow<T1>,
flow2: Flow<T2>,
Expand All @@ -137,7 +132,6 @@ public inline fun <T1, T2, T3, R> combine(
* The receiver of the [transform] is [FlowCollector] and thus `transform` is a
* generic function that may transform emitted element, skip it or emit it multiple times.
*/
@ExperimentalCoroutinesApi
public inline fun <T1, T2, T3, R> combineTransform(
flow: Flow<T1>,
flow2: Flow<T2>,
Expand All @@ -155,7 +149,6 @@ public inline fun <T1, T2, T3, R> combineTransform(
* Returns a [Flow] whose values are generated with [transform] function by combining
* the most recently emitted values by each flow.
*/
@ExperimentalCoroutinesApi
public inline fun <T1, T2, T3, T4, R> combine(
flow: Flow<T1>,
flow2: Flow<T2>,
Expand All @@ -177,7 +170,6 @@ public inline fun <T1, T2, T3, T4, R> combine(
* The receiver of the [transform] is [FlowCollector] and thus `transform` is a
* generic function that may transform emitted element, skip it or emit it multiple times.
*/
@ExperimentalCoroutinesApi
public inline fun <T1, T2, T3, T4, R> combineTransform(
flow: Flow<T1>,
flow2: Flow<T2>,
Expand All @@ -197,7 +189,6 @@ public inline fun <T1, T2, T3, T4, R> combineTransform(
* Returns a [Flow] whose values are generated with [transform] function by combining
* the most recently emitted values by each flow.
*/
@ExperimentalCoroutinesApi
public inline fun <T1, T2, T3, T4, T5, R> combine(
flow: Flow<T1>,
flow2: Flow<T2>,
Expand All @@ -221,7 +212,6 @@ public inline fun <T1, T2, T3, T4, T5, R> combine(
* The receiver of the [transform] is [FlowCollector] and thus `transform` is a
* generic function that may transform emitted element, skip it or emit it multiple times.
*/
@ExperimentalCoroutinesApi
public inline fun <T1, T2, T3, T4, T5, R> combineTransform(
flow: Flow<T1>,
flow2: Flow<T2>,
Expand All @@ -243,7 +233,6 @@ public inline fun <T1, T2, T3, T4, T5, R> combineTransform(
* Returns a [Flow] whose values are generated with [transform] function by combining
* the most recently emitted values by each flow.
*/
@ExperimentalCoroutinesApi
public inline fun <reified T, R> combine(
vararg flows: Flow<T>,
crossinline transform: suspend (Array<T>) -> R
Expand All @@ -257,7 +246,6 @@ public inline fun <reified T, R> combine(
* The receiver of the [transform] is [FlowCollector] and thus `transform` is a
* generic function that may transform emitted element, skip it or emit it multiple times.
*/
@ExperimentalCoroutinesApi
public inline fun <reified T, R> combineTransform(
vararg flows: Flow<T>,
@BuilderInference crossinline transform: suspend FlowCollector<R>.(Array<T>) -> Unit
Expand All @@ -269,7 +257,6 @@ public inline fun <reified T, R> combineTransform(
* Returns a [Flow] whose values are generated with [transform] function by combining
* the most recently emitted values by each flow.
*/
@ExperimentalCoroutinesApi
public inline fun <reified T, R> combine(
flows: Iterable<Flow<T>>,
crossinline transform: suspend (Array<T>) -> R
Expand All @@ -289,7 +276,6 @@ public inline fun <reified T, R> combine(
* The receiver of the [transform] is [FlowCollector] and thus `transform` is a
* generic function that may transform emitted element, skip it or emit it multiple times.
*/
@ExperimentalCoroutinesApi
public inline fun <reified T, R> combineTransform(
flows: Iterable<Flow<T>>,
@BuilderInference crossinline transform: suspend FlowCollector<R>.(Array<T>) -> Unit
Expand All @@ -313,5 +299,4 @@ public inline fun <reified T, R> combineTransform(
* }
* ```
*/
@ExperimentalCoroutinesApi
public fun <T1, T2, R> Flow<T1>.zip(other: Flow<T2>, transform: suspend (T1, T2) -> R): Flow<R> = zipImpl(this, other, transform)
4 changes: 0 additions & 4 deletions kotlinx-coroutines-core/common/src/flow/terminal/Collect.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public suspend fun Flow<*>.collect(): Unit = collect(NopCollector)
*
* Note that resulting value of [launchIn] is not used the provided scope takes care of cancellation.
*/
@ExperimentalCoroutinesApi // tentatively stable in 1.3.0
public fun <T> Flow<T>.launchIn(scope: CoroutineScope): Job = scope.launch {
collect() // tail-call
}
Expand Down Expand Up @@ -80,7 +79,6 @@ public suspend inline fun <T> Flow<T>.collect(crossinline action: suspend (value
*
* See also [collect] and [withIndex].
*/
@ExperimentalCoroutinesApi
public suspend inline fun <T> Flow<T>.collectIndexed(crossinline action: suspend (index: Int, value: T) -> Unit): Unit =
collect(object : FlowCollector<T> {
private var index = 0
Expand Down Expand Up @@ -108,7 +106,6 @@ public suspend inline fun <T> Flow<T>.collectIndexed(crossinline action: suspend
*
* prints "Collecting 1, Collecting 2, 2 collected"
*/
@ExperimentalCoroutinesApi
public suspend fun <T> Flow<T>.collectLatest(action: suspend (value: T) -> Unit) {
/*
* Implementation note:
Expand All @@ -131,5 +128,4 @@ public suspend fun <T> Flow<T>.collectLatest(action: suspend (value: T) -> Unit)
* It is a shorthand for `flow.collect { value -> emit(value) }`.
*/
@BuilderInference
@ExperimentalCoroutinesApi
public suspend inline fun <T> FlowCollector<T>.emitAll(flow: Flow<T>): Unit = flow.collect(this)
2 changes: 0 additions & 2 deletions kotlinx-coroutines-core/common/src/flow/terminal/Count.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import kotlin.jvm.*
/**
* Returns the number of elements in this flow.
*/
@ExperimentalCoroutinesApi
public suspend fun <T> Flow<T>.count(): Int {
var i = 0
collect {
Expand All @@ -26,7 +25,6 @@ public suspend fun <T> Flow<T>.count(): Int {
/**
* Returns the number of elements matching the given predicate.
*/
@ExperimentalCoroutinesApi
public suspend fun <T> Flow<T>.count(predicate: suspend (T) -> Boolean): Int {
var i = 0
collect { value ->
Expand Down
2 changes: 0 additions & 2 deletions kotlinx-coroutines-core/common/src/flow/terminal/Reduce.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import kotlin.jvm.*
* Accumulates value starting with the first element and applying [operation] to current accumulator value and each element.
* Throws [NoSuchElementException] if flow was empty.
*/
@ExperimentalCoroutinesApi
public suspend fun <S, T : S> Flow<T>.reduce(operation: suspend (accumulator: S, value: T) -> S): S {
var accumulator: Any? = NULL

Expand All @@ -38,7 +37,6 @@ public suspend fun <S, T : S> Flow<T>.reduce(operation: suspend (accumulator: S,
/**
* Accumulates value starting with [initial] value and applying [operation] current accumulator value and each element
*/
@ExperimentalCoroutinesApi
public suspend inline fun <T, R> Flow<T>.fold(
initial: R,
crossinline operation: suspend (acc: R, value: T) -> R
Expand Down

0 comments on commit 5b00e48

Please # to comment.