Skip to content

Commit 5b00e48

Browse files
authored
Remove experimental status from Flow API (#1963)
* 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
1 parent 515e86a commit 5b00e48

File tree

11 files changed

+0
-42
lines changed

11 files changed

+0
-42
lines changed

kotlinx-coroutines-core/common/src/flow/Channels.kt

-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import kotlinx.coroutines.flow.internal.unsafeFlow as flow
2323
* This function provides a more efficient shorthand for `channel.consumeEach { value -> emit(value) }`.
2424
* See [consumeEach][ReceiveChannel.consumeEach].
2525
*/
26-
@ExperimentalCoroutinesApi // since version 1.3.0
2726
public suspend fun <T> FlowCollector<T>.emitAll(channel: ReceiveChannel<T>): Unit =
2827
emitAllImpl(channel, consume = true)
2928

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

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

112109
/**

kotlinx-coroutines-core/common/src/flow/operators/Context.kt

-3
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ import kotlin.jvm.*
104104
* [RENDEZVOUS][Channel.RENDEZVOUS], [UNLIMITED][Channel.UNLIMITED] or a non-negative value indicating
105105
* an explicitly requested size.
106106
*/
107-
@ExperimentalCoroutinesApi
108107
public fun <T> Flow<T>.buffer(capacity: Int = BUFFERED): Flow<T> {
109108
require(capacity >= 0 || capacity == BUFFERED || capacity == CONFLATED) {
110109
"Buffer size should be non-negative, BUFFERED, or CONFLATED, but was $capacity"
@@ -147,7 +146,6 @@ public fun <T> Flow<T>.buffer(capacity: Int = BUFFERED): Flow<T> {
147146
* always fused so that only one properly configured channel is used for execution.
148147
* **Conflation takes precedence over `buffer()` calls with any other capacity.**
149148
*/
150-
@ExperimentalCoroutinesApi
151149
public fun <T> Flow<T>.conflate(): Flow<T> = buffer(CONFLATED)
152150

153151
/**
@@ -194,7 +192,6 @@ public fun <T> Flow<T>.conflate(): Flow<T> = buffer(CONFLATED)
194192
*
195193
* @throws [IllegalArgumentException] if provided context contains [Job] instance.
196194
*/
197-
@ExperimentalCoroutinesApi
198195
public fun <T> Flow<T>.flowOn(context: CoroutineContext): Flow<T> {
199196
checkFlowContext(context)
200197
return when {

kotlinx-coroutines-core/common/src/flow/operators/Distinct.kt

-3
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,19 @@ import kotlinx.coroutines.flow.internal.unsafeFlow as flow
1515
/**
1616
* Returns flow where all subsequent repetitions of the same value are filtered out.
1717
*/
18-
@ExperimentalCoroutinesApi
1918
public fun <T> Flow<T>.distinctUntilChanged(): Flow<T> = distinctUntilChangedBy { it }
2019

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

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

kotlinx-coroutines-core/common/src/flow/operators/Emitters.kt

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import kotlin.jvm.*
3434
* }
3535
* ```
3636
*/
37-
@ExperimentalCoroutinesApi
3837
public inline fun <T, R> Flow<T>.transform(
3938
@BuilderInference crossinline transform: suspend FlowCollector<R>.(value: T) -> Unit
4039
): Flow<R> = flow { // Note: safe flow is used here, because collector is exposed to transform on each operation

kotlinx-coroutines-core/common/src/flow/operators/Errors.kt

-3
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ import kotlinx.coroutines.flow.internal.unsafeFlow as flow
5454
* retry an original flow use [retryWhen] operator that can retry the flow multiple times without
5555
* introducing ever-growing stack of suspending calls.
5656
*/
57-
@ExperimentalCoroutinesApi // tentatively stable in 1.3.0
5857
public fun <T> Flow<T>.catch(action: suspend FlowCollector<T>.(cause: Throwable) -> Unit): Flow<T> =
5958
flow {
6059
val exception = catchImpl(this)
@@ -117,7 +116,6 @@ public fun <T> Flow<T>.onErrorCollect(
117116
*
118117
* @throws IllegalArgumentException when [retries] is not positive.
119118
*/
120-
@ExperimentalCoroutinesApi // tentatively stable in 1.3.0
121119
public fun <T> Flow<T>.retry(
122120
retries: Long = Long.MAX_VALUE,
123121
predicate: suspend (cause: Throwable) -> Boolean = { true }
@@ -169,7 +167,6 @@ public fun <T> Flow<T>.retry(
169167
*
170168
* See [catch] for more details.
171169
*/
172-
@ExperimentalCoroutinesApi // tentatively stable in 1.3.0
173170
public fun <T> Flow<T>.retryWhen(predicate: suspend FlowCollector<T>.(cause: Throwable, attempt: Long) -> Boolean): Flow<T> =
174171
flow {
175172
var attempt = 0L

kotlinx-coroutines-core/common/src/flow/operators/Limit.kt

-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
package kotlinx.coroutines.flow
99

10-
import kotlinx.coroutines.*
1110
import kotlinx.coroutines.flow.internal.*
1211
import kotlin.jvm.*
1312
import kotlinx.coroutines.flow.internal.unsafeFlow as flow
@@ -16,7 +15,6 @@ import kotlinx.coroutines.flow.internal.unsafeFlow as flow
1615
* Returns a flow that ignores first [count] elements.
1716
* Throws [IllegalArgumentException] if [count] is negative.
1817
*/
19-
@ExperimentalCoroutinesApi
2018
public fun <T> Flow<T>.drop(count: Int): Flow<T> {
2119
require(count >= 0) { "Drop count should be non-negative, but had $count" }
2220
return flow {
@@ -30,7 +28,6 @@ public fun <T> Flow<T>.drop(count: Int): Flow<T> {
3028
/**
3129
* Returns a flow containing all elements except first elements that satisfy the given predicate.
3230
*/
33-
@ExperimentalCoroutinesApi
3431
public fun <T> Flow<T>.dropWhile(predicate: suspend (T) -> Boolean): Flow<T> = flow {
3532
var matched = false
3633
collect { value ->
@@ -48,7 +45,6 @@ public fun <T> Flow<T>.dropWhile(predicate: suspend (T) -> Boolean): Flow<T> = f
4845
* When [count] elements are consumed, the original flow is cancelled.
4946
* Throws [IllegalArgumentException] if [count] is not positive.
5047
*/
51-
@ExperimentalCoroutinesApi
5248
public fun <T> Flow<T>.take(count: Int): Flow<T> {
5349
require(count > 0) { "Requested element count $count should be positive" }
5450
return flow {
@@ -75,7 +71,6 @@ private suspend fun <T> FlowCollector<T>.emitAbort(value: T) {
7571
/**
7672
* Returns a flow that contains first elements satisfying the given [predicate].
7773
*/
78-
@ExperimentalCoroutinesApi
7974
public fun <T> Flow<T>.takeWhile(predicate: suspend (T) -> Boolean): Flow<T> = flow {
8075
try {
8176
collect { value ->

kotlinx-coroutines-core/common/src/flow/operators/Transform.kt

-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ public inline fun <T, R: Any> Flow<T>.mapNotNull(crossinline transform: suspend
5959
/**
6060
* Returns a flow that wraps each element into [IndexedValue], containing value and its index (starting from zero).
6161
*/
62-
@ExperimentalCoroutinesApi
6362
public fun <T> Flow<T>.withIndex(): Flow<IndexedValue<T>> = flow {
6463
var index = 0
6564
collect { value ->

kotlinx-coroutines-core/common/src/flow/operators/Zip.kt

-15
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import kotlinx.coroutines.flow.internal.unsafeFlow as flow
3030
* This function is a shorthand for `flow.combineTransform(flow2) { a, b -> emit(transform(a, b)) }
3131
*/
3232
@JvmName("flowCombine")
33-
@ExperimentalCoroutinesApi
3433
public fun <T1, T2, R> Flow<T1>.combine(flow: Flow<T2>, transform: suspend (a: T1, b: T2) -> R): Flow<R> = flow {
3534
combineTransformInternal(this@combine, flow) { a, b ->
3635
emit(transform(a, b))
@@ -52,7 +51,6 @@ public fun <T1, T2, R> Flow<T1>.combine(flow: Flow<T2>, transform: suspend (a: T
5251
*
5352
* This function is a shorthand for `combineTransform(flow, flow2) { a, b -> emit(transform(a, b)) }
5453
*/
55-
@ExperimentalCoroutinesApi
5654
public fun <T1, T2, R> combine(flow: Flow<T1>, flow2: Flow<T2>, transform: suspend (a: T1, b: T2) -> R): Flow<R> =
5755
flow.combine(flow2, transform)
5856

@@ -74,7 +72,6 @@ public fun <T1, T2, R> combine(flow: Flow<T1>, flow2: Flow<T2>, transform: suspe
7472
* ```
7573
*/
7674
@JvmName("flowCombineTransform")
77-
@ExperimentalCoroutinesApi
7875
public fun <T1, T2, R> Flow<T1>.combineTransform(
7976
flow: Flow<T2>,
8077
@BuilderInference transform: suspend FlowCollector<R>.(a: T1, b: T2) -> Unit
@@ -101,7 +98,6 @@ public fun <T1, T2, R> Flow<T1>.combineTransform(
10198
* }
10299
* ```
103100
*/
104-
@ExperimentalCoroutinesApi
105101
public fun <T1, T2, R> combineTransform(
106102
flow: Flow<T1>,
107103
flow2: Flow<T2>,
@@ -117,7 +113,6 @@ public fun <T1, T2, R> combineTransform(
117113
* Returns a [Flow] whose values are generated with [transform] function by combining
118114
* the most recently emitted values by each flow.
119115
*/
120-
@ExperimentalCoroutinesApi
121116
public inline fun <T1, T2, T3, R> combine(
122117
flow: Flow<T1>,
123118
flow2: Flow<T2>,
@@ -137,7 +132,6 @@ public inline fun <T1, T2, T3, R> combine(
137132
* The receiver of the [transform] is [FlowCollector] and thus `transform` is a
138133
* generic function that may transform emitted element, skip it or emit it multiple times.
139134
*/
140-
@ExperimentalCoroutinesApi
141135
public inline fun <T1, T2, T3, R> combineTransform(
142136
flow: Flow<T1>,
143137
flow2: Flow<T2>,
@@ -155,7 +149,6 @@ public inline fun <T1, T2, T3, R> combineTransform(
155149
* Returns a [Flow] whose values are generated with [transform] function by combining
156150
* the most recently emitted values by each flow.
157151
*/
158-
@ExperimentalCoroutinesApi
159152
public inline fun <T1, T2, T3, T4, R> combine(
160153
flow: Flow<T1>,
161154
flow2: Flow<T2>,
@@ -177,7 +170,6 @@ public inline fun <T1, T2, T3, T4, R> combine(
177170
* The receiver of the [transform] is [FlowCollector] and thus `transform` is a
178171
* generic function that may transform emitted element, skip it or emit it multiple times.
179172
*/
180-
@ExperimentalCoroutinesApi
181173
public inline fun <T1, T2, T3, T4, R> combineTransform(
182174
flow: Flow<T1>,
183175
flow2: Flow<T2>,
@@ -197,7 +189,6 @@ public inline fun <T1, T2, T3, T4, R> combineTransform(
197189
* Returns a [Flow] whose values are generated with [transform] function by combining
198190
* the most recently emitted values by each flow.
199191
*/
200-
@ExperimentalCoroutinesApi
201192
public inline fun <T1, T2, T3, T4, T5, R> combine(
202193
flow: Flow<T1>,
203194
flow2: Flow<T2>,
@@ -221,7 +212,6 @@ public inline fun <T1, T2, T3, T4, T5, R> combine(
221212
* The receiver of the [transform] is [FlowCollector] and thus `transform` is a
222213
* generic function that may transform emitted element, skip it or emit it multiple times.
223214
*/
224-
@ExperimentalCoroutinesApi
225215
public inline fun <T1, T2, T3, T4, T5, R> combineTransform(
226216
flow: Flow<T1>,
227217
flow2: Flow<T2>,
@@ -243,7 +233,6 @@ public inline fun <T1, T2, T3, T4, T5, R> combineTransform(
243233
* Returns a [Flow] whose values are generated with [transform] function by combining
244234
* the most recently emitted values by each flow.
245235
*/
246-
@ExperimentalCoroutinesApi
247236
public inline fun <reified T, R> combine(
248237
vararg flows: Flow<T>,
249238
crossinline transform: suspend (Array<T>) -> R
@@ -257,7 +246,6 @@ public inline fun <reified T, R> combine(
257246
* The receiver of the [transform] is [FlowCollector] and thus `transform` is a
258247
* generic function that may transform emitted element, skip it or emit it multiple times.
259248
*/
260-
@ExperimentalCoroutinesApi
261249
public inline fun <reified T, R> combineTransform(
262250
vararg flows: Flow<T>,
263251
@BuilderInference crossinline transform: suspend FlowCollector<R>.(Array<T>) -> Unit
@@ -269,7 +257,6 @@ public inline fun <reified T, R> combineTransform(
269257
* Returns a [Flow] whose values are generated with [transform] function by combining
270258
* the most recently emitted values by each flow.
271259
*/
272-
@ExperimentalCoroutinesApi
273260
public inline fun <reified T, R> combine(
274261
flows: Iterable<Flow<T>>,
275262
crossinline transform: suspend (Array<T>) -> R
@@ -289,7 +276,6 @@ public inline fun <reified T, R> combine(
289276
* The receiver of the [transform] is [FlowCollector] and thus `transform` is a
290277
* generic function that may transform emitted element, skip it or emit it multiple times.
291278
*/
292-
@ExperimentalCoroutinesApi
293279
public inline fun <reified T, R> combineTransform(
294280
flows: Iterable<Flow<T>>,
295281
@BuilderInference crossinline transform: suspend FlowCollector<R>.(Array<T>) -> Unit
@@ -313,5 +299,4 @@ public inline fun <reified T, R> combineTransform(
313299
* }
314300
* ```
315301
*/
316-
@ExperimentalCoroutinesApi
317302
public fun <T1, T2, R> Flow<T1>.zip(other: Flow<T2>, transform: suspend (T1, T2) -> R): Flow<R> = zipImpl(this, other, transform)

kotlinx-coroutines-core/common/src/flow/terminal/Collect.kt

-4
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ public suspend fun Flow<*>.collect(): Unit = collect(NopCollector)
4646
*
4747
* Note that resulting value of [launchIn] is not used the provided scope takes care of cancellation.
4848
*/
49-
@ExperimentalCoroutinesApi // tentatively stable in 1.3.0
5049
public fun <T> Flow<T>.launchIn(scope: CoroutineScope): Job = scope.launch {
5150
collect() // tail-call
5251
}
@@ -80,7 +79,6 @@ public suspend inline fun <T> Flow<T>.collect(crossinline action: suspend (value
8079
*
8180
* See also [collect] and [withIndex].
8281
*/
83-
@ExperimentalCoroutinesApi
8482
public suspend inline fun <T> Flow<T>.collectIndexed(crossinline action: suspend (index: Int, value: T) -> Unit): Unit =
8583
collect(object : FlowCollector<T> {
8684
private var index = 0
@@ -108,7 +106,6 @@ public suspend inline fun <T> Flow<T>.collectIndexed(crossinline action: suspend
108106
*
109107
* prints "Collecting 1, Collecting 2, 2 collected"
110108
*/
111-
@ExperimentalCoroutinesApi
112109
public suspend fun <T> Flow<T>.collectLatest(action: suspend (value: T) -> Unit) {
113110
/*
114111
* Implementation note:
@@ -131,5 +128,4 @@ public suspend fun <T> Flow<T>.collectLatest(action: suspend (value: T) -> Unit)
131128
* It is a shorthand for `flow.collect { value -> emit(value) }`.
132129
*/
133130
@BuilderInference
134-
@ExperimentalCoroutinesApi
135131
public suspend inline fun <T> FlowCollector<T>.emitAll(flow: Flow<T>): Unit = flow.collect(this)

kotlinx-coroutines-core/common/src/flow/terminal/Count.kt

-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import kotlin.jvm.*
1313
/**
1414
* Returns the number of elements in this flow.
1515
*/
16-
@ExperimentalCoroutinesApi
1716
public suspend fun <T> Flow<T>.count(): Int {
1817
var i = 0
1918
collect {
@@ -26,7 +25,6 @@ public suspend fun <T> Flow<T>.count(): Int {
2625
/**
2726
* Returns the number of elements matching the given predicate.
2827
*/
29-
@ExperimentalCoroutinesApi
3028
public suspend fun <T> Flow<T>.count(predicate: suspend (T) -> Boolean): Int {
3129
var i = 0
3230
collect { value ->

kotlinx-coroutines-core/common/src/flow/terminal/Reduce.kt

-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import kotlin.jvm.*
1717
* Accumulates value starting with the first element and applying [operation] to current accumulator value and each element.
1818
* Throws [NoSuchElementException] if flow was empty.
1919
*/
20-
@ExperimentalCoroutinesApi
2120
public suspend fun <S, T : S> Flow<T>.reduce(operation: suspend (accumulator: S, value: T) -> S): S {
2221
var accumulator: Any? = NULL
2322

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

0 commit comments

Comments
 (0)