Skip to content

Commit 7bc3e46

Browse files
committed
Add forEach to migrations
Fixes #1244
1 parent 2dcfe92 commit 7bc3e46

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

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)