Skip to content

Instantly share code, notes, and snippets.

@nejckorasa
Created July 11, 2018 14:36
Show Gist options
  • Select an option

  • Save nejckorasa/28295f25734c4297e0cd774d024ede1d to your computer and use it in GitHub Desktop.

Select an option

Save nejckorasa/28295f25734c4297e0cd774d024ede1d to your computer and use it in GitHub Desktop.
Functions to use map and async calls in Kotlin
// async kotlin collections map
suspend fun <A, B> List<A>.awmap(f: suspend (A) -> B): List<B> {
return map { async { f(it) } } // create async function call
.map { it.await() } // await it on next map call
}
suspend fun <A, B> List<A>.amap(f: suspend (A) -> B): List<Deferred<B>> = map { async { f(it) } } // create async function call
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment