Hey! so is I am getting started with multiprocessi...
# coroutines
a
Hey! so is I am getting started with multiprocessing and wanted to know if there is something similar to pythons Pool.map() in kotlin?
c
I'm not familiar with Python's Pool, but I guess there are too meanings it could have: • process a known list of elements concurrently • process elements concurrently as they come in For solution 2: this used to exist on Channel, but I think it was removed (not sure though). For solution 1:
Copy code
suspend fun <I, O> List<I>.parallelMap(transform: suspend (I) -> O): List<O> = coroutineScope {
  this
    .map { launch { transform(it) } }
    .map { it.await() }
}
Usage:
Copy code
listOf(1, 2, 3, 4)
  .parallelMap { expensiveOperation(it) }