A Retrofit 2 (Experimental) CallAdapter.Factory
bringing map and flatmap to calls.
Add JitPack repository to your build.gradle
file
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Add the Dependency
dependencies {
implementation "com.github.fp-in-bo:kall:0.0.1"
}
Add KallAdapterFactory
as a Call
adapter when building your Retrofit
instance:
val retrofit = Retrofit.Builder()
.baseUrl("https://example.com/")
.addCallAdapterFactory(KallAdapterFactory())
.build()
Your service methods can now use Kall
as their return type.
interface GitHubAPI {
@GET("users/{username}")
fun getUser(@Path("username") userName: String): Kall<User>
@GET
fun getFollowers(@Url url: String): Kall<List<User>>
}
Your can now map
api.getUser("dcampogiani").map { it.login.toUpperCase() }
And flatmap
api.getUser("dcampogiani").flatMap {
api.getFollowers(it.followersUrl)
}