-
-
Save PatilShreyas/865de489ca1007afaa44b7f6c87e1096 to your computer and use it in GitHub Desktop.
This file contains 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> 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