Skip to content

Instantly share code, notes, and snippets.

@aballano
Created March 12, 2017 16:57
Show Gist options
  • Save aballano/76220da7b9edb6f88571623d805b6b92 to your computer and use it in GitHub Desktop.
Save aballano/76220da7b9edb6f88571623d805b6b92 to your computer and use it in GitHub Desktop.
Kotlin ternary operator
// Source: http://stackoverflow.com/a/39687177/616119
infix fun <T> Boolean.then(param: T): T? = if (this) param else null
// Usage:
println(condition then "true" ?: "false")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment