Created
July 11, 2018 14:36
-
-
Save nejckorasa/28295f25734c4297e0cd774d024ede1d to your computer and use it in GitHub Desktop.
Functions to use map and async calls in Kotlin
This file contains hidden or 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
| // 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