Last active
March 13, 2020 17:17
-
-
Save gacordeiro/05ae0a8566e070915b072b4f7fe1f021 to your computer and use it in GitHub Desktop.
Ternary in Kotlin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class _Ternary<out T>(val condition: Boolean, val ifTrue: T) | |
infix fun <T> Boolean.then(ifTrue: T): _Ternary<T> = _Ternary(this, ifTrue) | |
infix fun <T> _Ternary<T>.otherwise(ifFalse: T): T = if (condition) ifTrue else ifFalse | |
const val tellMeTheTruth: Boolean = true | |
val result: String = tellMeTheTruth then "I'll believe you" otherwise "I'll never trust you" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment