Ansh Tyagi
11/09/2021, 5:58 PMCLOVIS
11/20/2021, 11:01 AMsuspend fun <I, O> List<I>.parallelMap(transform: suspend (I) -> O): List<O> = coroutineScope {
this
.map { launch { transform(it) } }
.map { it.await() }
}
Usage:
listOf(1, 2, 3, 4)
.parallelMap { expensiveOperation(it) }