Created
January 26, 2022 14:05
-
-
Save brh/24185e7ca0cee34e53ce7aab42129dd2 to your computer and use it in GitHub Desktop.
Pokemon multi call
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
override suspend fun getPokemonList(offset: Int): PokemonPageResponse { | |
val listResult = api.getPokemonList(offset) | |
val uiList = listResult.results.map { item -> | |
val id = item.url.extractIdFromUrl() | |
val deferred: Deferred<PokemonDetailUI> = repoScope.async(start = CoroutineStart.LAZY) { | |
val result = api.getPokemonDetails(id) | |
PokemonDetailUI(result.sprites.frontDefault, emptyList(), PokemonType("f")) | |
} | |
PokemonUI(item.name, id, deferred) | |
} | |
return PokemonPageResponse( | |
listResult.next?.getOffset(), | |
listResult.previous?.getOffset(), | |
uiList | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment