Last active
May 5, 2019 20:10
-
-
Save JacquesSmuts/499cab2b907298bc03de8d02d19c22c0 to your computer and use it in GitHub Desktop.
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
| import kotlin.reflect.KFunction2 // You have to import this manually | |
| inline fun <reified Service: RetroService, Input, Result> doApiCallWithArg( | |
| services: List<RetroService>, | |
| apiCall: KFunction2<Service, Input, Result>, | |
| input: Input | |
| ): Result? { | |
| Log.v(TAG, "Attempting to do \$apiCall on \$services with argument \$input") | |
| services.filterIsInstance<Service>() | |
| .forEach { service -> | |
| val result = apiCall(service, input) | |
| Log.i(TAG, "Returned result $result") | |
| return result | |
| } | |
| Log.d(TAG, "None of the services were compatible, returning null") | |
| return null | |
| } | |
| fun listGitHubReposForJacques(services: List<RetroService>): List<GitHubRepo>? { | |
| val username = "JacquesSmuts" | |
| return doApiCallWithArg(services, GitHubService::listGitHubRepos, username) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment