Created
June 15, 2024 20:58
-
-
Save martin-tarjanyi/9b843e99e45abc6a200fe51e5e1eb0f4 to your computer and use it in GitHub Desktop.
Kotlin flow concurrent map
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun <T, R> Flow<T>.concurrentMap( | |
| concurrency: Int, | |
| dispatcher: CoroutineDispatcher = Dispatchers.Unconfined, | |
| transform: suspend (value: T) -> R, | |
| ): Flow<R> = | |
| map { flow { emit(transform(it)) }.flowOn(dispatcher) } | |
| .flattenMerge(concurrency) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment