Skip to content

Instantly share code, notes, and snippets.

@JacquesSmuts
Last active May 5, 2019 20:10
Show Gist options
  • Select an option

  • Save JacquesSmuts/499cab2b907298bc03de8d02d19c22c0 to your computer and use it in GitHub Desktop.

Select an option

Save JacquesSmuts/499cab2b907298bc03de8d02d19c22c0 to your computer and use it in GitHub Desktop.
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