Skip to content

Latest commit

 

History

History
82 lines (70 loc) · 1.9 KB

README.md

File metadata and controls

82 lines (70 loc) · 1.9 KB

CircleCI Download

Churros

This is a humble library dedicated to making the life of developers easier.

Installation

Be sure to have JCenter in the base gradle file.

allprojects {
    repositories {
        jcenter()
    }
}

Then it's a matter of adding the dependency.

dependencies {
    // Churros
    implementation "com.asapp.churros:churros:0.2.0"
}

Things we have

runIf

    val okHttpClient = OkHttpClient.Builder()
        .addInterceptor(interceptor)
        .runIf(isVerbose) {
            val loggingInterceptor =
                HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY)

            addNetworkInterceptor(loggingInterceptor)
        }
        .build()

exhaustive

This code will work happily.

    enum class Snack {
        HUMUS, CHIPS, GUACAMOLE
    }
    val today = GUACAMOLE

    when (today) {
        HUMUS -> getPita()
        CHIPS -> buyGuacamole()
    }

This code will complain that you missed thinking about Guacamole

    enum class Snack {
        HUMMUS, CHIPS, GUACAMOLE
    }
    val today = GUACAMOLE

    when (today) {
        HUMMUS -> getPita()
        CHIPS -> buyGuacamole()
    }
    .exhaustive()

Context.toast

    activity.toast(R.string.auth_error)

Single<List>.flatMapList

        fun getAccountInDB(id: Int): Single<Account> = Single.just(Account(id))
        fun getItemsFromNetwork(): Single<List<Int>> = Single.just(listOf(101, 42, 3))

        val result: Single<List<Account>> = getItemsFromNetwork()
            .flatMapList { getAccountInDB(it) }