Skip to content

Instantly share code, notes, and snippets.

View dariushm2's full-sized avatar

Dariush Malek dariushm2

View GitHub Profile
@dariushm2
dariushm2 / ElvisOperator.kt
Last active May 15, 2023 02:14
Elvis Operator in Kotlin
data class ElvisOperator<T>(
val condition: Boolean?,
val trueValue: T?,
) {
operator fun minus(falseValue: T?): T? =
if (condition == true) trueValue else falseValue
}
operator fun <T> Boolean?.plus(trueValue: T?) =
ElvisBuilder(this, trueValue)