Skip to content

Commit 2d2a1b7

Browse files
committed
Add forEach to migrations
Fixes #1244
1 parent 6b59719 commit 2d2a1b7

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
@@ -880,6 +880,7 @@ public final class kotlinx/coroutines/flow/MigrationKt {
880880
public static final fun concatMap (Lkotlinx/coroutines/flow/Flow;Lkotlin/jvm/functions/Function1;)Lkotlinx/coroutines/flow/Flow;
881881
public static final fun flatMap (Lkotlinx/coroutines/flow/Flow;Lkotlin/jvm/functions/Function2;)Lkotlinx/coroutines/flow/Flow;
882882
public static final fun flatten (Lkotlinx/coroutines/flow/Flow;)Lkotlinx/coroutines/flow/Flow;
883+
public static final fun forEach (Lkotlinx/coroutines/flow/Flow;Lkotlin/jvm/functions/Function2;)V
883884
public static final fun merge (Lkotlinx/coroutines/flow/Flow;)Lkotlinx/coroutines/flow/Flow;
884885
public static final fun observeOn (Lkotlinx/coroutines/flow/Flow;Lkotlin/coroutines/CoroutineContext;)Lkotlinx/coroutines/flow/Flow;
885886
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
@@ -225,3 +225,18 @@ public fun <T, R> Flow<T>.compose(transformer: Flow<T>.() -> Flow<R>): Flow<R> =
225225
replaceWith = ReplaceWith("drop(count)")
226226
)
227227
public fun <T> Flow<T>.skip(count: Int): Flow<T> = error("Should not be called")
228+
229+
/**
230+
* Flow extension to iterate over elements is [collect].
231+
* Foreach wasn't introduced deliberately to avoid confusion.
232+
* Flow is not a collection, iteration over it may be not idempotent
233+
* and can *launch* computations with side-effects.
234+
* This behaviour is not reflected in [forEach] name.
235+
* @suppress
236+
*/
237+
@Deprecated(
238+
level = DeprecationLevel.ERROR,
239+
message = "Flow analogue of 'forEach' is 'collect'",
240+
replaceWith = ReplaceWith("collect(block)")
241+
)
242+
public fun <T> Flow<T>.forEach(action: suspend (value: T) -> Unit): Unit = error("Should not be called")

0 commit comments

Comments
 (0)