se.ansman.kotshi.AnyExt.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of compiler Show documentation
Show all versions of compiler Show documentation
An annotations processor that generates Moshi adapters from Kotlin data classes
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