Skip to content

Instantly share code, notes, and snippets.

@danieloskarsson
Created June 13, 2020 09:36
Show Gist options
  • Save danieloskarsson/249f8ea3d3a1862b1ac19cdcf3a3178b to your computer and use it in GitHub Desktop.
Save danieloskarsson/249f8ea3d3a1862b1ac19cdcf3a3178b to your computer and use it in GitHub Desktop.
class If<T>(val any: T?, private val i: (T) -> Unit) {
infix fun Else(e: () -> Unit) {
if (any == null) e()
else i(any)
}
}
Usage:
If (nullableString) {
} Else {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment