Skip to content

Commit 4a33261

Browse files
committed
Add forEach to migrations
Fixes #1244
1 parent 2dcfe92 commit 4a33261

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

binary-compatibility-validator/reference-public-api/kotlinx-coroutines-core.txt

+1
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,7 @@ public final class kotlinx/coroutines/flow/MigrationKt {
876876
public static final fun concatMap (Lkotlinx/coroutines/flow/Flow;Lkotlin/jvm/functions/Function1;)Lkotlinx/coroutines/flow/Flow;
877877
public static final fun flatMap (Lkotlinx/coroutines/flow/Flow;Lkotlin/jvm/functions/Function2;)Lkotlinx/coroutines/flow/Flow;
878878
public static final fun flatten (Lkotlinx/coroutines/flow/Flow;)Lkotlinx/coroutines/flow/Flow;
879+
public static final fun forEach (Lkotlinx/coroutines/flow/Flow;Lkotlin/jvm/functions/Function2;)V
879880
public static final fun merge (Lkotlinx/coroutines/flow/Flow;)Lkotlinx/coroutines/flow/Flow;
880881
public static final fun observeOn (Lkotlinx/coroutines/flow/Flow;Lkotlin/coroutines/CoroutineContext;)Lkotlinx/coroutines/flow/Flow;
881882
public static final fun onErrorResume (Lkotlinx/coroutines/flow/Flow;Lkotlinx/coroutines/flow/Flow;)Lkotlinx/coroutines/flow/Flow;

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

+15
Original file line numberDiff line numberDiff line change
@@ -240,3 +240,18 @@ public fun <T, R> Flow<T>.compose(transformer: Flow<T>.() -> Flow<R>): Flow<R> =
240240
replaceWith = ReplaceWith("drop(count)")
241241
)
242242
public fun <T> Flow<T>.skip(count: Int): Flow<T> = error("Should not be called")
243+
244+
/**
245+
* Flow extension to iterate over elements is [collect].
246+
* Foreach wasn't introduced deliberately to avoid confusion.
247+
* Flow is not a collection, iteration over it may be not idempotent
248+
* and can *launch* computations with side-effects.
249+
* This behaviour is not reflected in [forEach] name.
250+
* @suppress
251+
*/
252+
@Deprecated(
253+
level = DeprecationLevel.ERROR,
254+
message = "Flow analogue of 'forEach' is 'collect'",
255+
replaceWith = ReplaceWith("collect(block)")
256+
)
257+
public fun <T> Flow<T>.forEach(action: suspend (value: T) -> Unit): Unit = error("Should not be called")

0 commit comments

Comments
 (0)