Skip to content

Latest commit

 

History

History
65 lines (50 loc) · 1.58 KB

README.md

File metadata and controls

65 lines (50 loc) · 1.58 KB

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