All Downloads are FREE. Search and download functionalities are using the official Maven repository.

se.ansman.kotshi.AnyExt.kt Maven / Gradle / Ivy

Go to download

An annotations processor that generates Moshi adapters from Kotlin data classes

The newest version!
package se.ansman.kotshi

inline fun  T.applyIf(applyIf: Boolean, block: T.() -> Unit): T = apply {
    if (applyIf) block(this)
}

inline fun  T.applyEach(iterable: Iterable, block: T.(I) -> Unit): T = apply {
    iterable.forEach { block(this, it) }
}

inline fun  T.applyEachIndexed(iterable: Iterable, block: T.(Int, I) -> Unit): T = apply {
    iterable.forEachIndexed { index, element ->  block(this, index, element) }
}

inline fun  T.runIf(runIf: Boolean, block: T.() -> T): T = if (runIf) block(this) else this