Skip to content
/ kall Public

A Retrofit 2 (Experimental) CallAdapter.Factory bringing map and flatmap to calls.

Notifications You must be signed in to change notification settings

fp-in-bo/kall

Repository files navigation

Kall Release Build Status

A Retrofit 2 (Experimental) CallAdapter.Factory bringing map and flatmap to calls.

Usage

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)
        }

Thanks

  • Jake Wharton and Square for their open source adapters
  • azanin and al333z for teaching me functional programming

About

A Retrofit 2 (Experimental) CallAdapter.Factory bringing map and flatmap to calls.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages