Skip to content

Instantly share code, notes, and snippets.

@PatilShreyas
Last active March 31, 2022 17:54
Show Gist options
  • Save PatilShreyas/865de489ca1007afaa44b7f6c87e1096 to your computer and use it in GitHub Desktop.
Save PatilShreyas/865de489ca1007afaa44b7f6c87e1096 to your computer and use it in GitHub Desktop.
fun <T, R> Iterable<T>.map(
dispatcher: CoroutineDispatcher,
transform: (T) -> R
): List<R> = runBlocking {
map { item -> async(dispatcher) { transform(item) } }.awaitAll()
}
fun doSomething(users: List<User>) {
users.map(Dispatchers.Default) { user -> user.toSomething() /* `toSomething()` is heavy method */ }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment