Skip to content

Instantly share code, notes, and snippets.

@PatilShreyas
Last active Mar 31, 2022
Embed
What would you like to do?
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