Skip to content

Instantly share code, notes, and snippets.

@petitJAM
Last active September 14, 2021 20:53
Show Gist options
  • Save petitJAM/62141534a0b672bc4526234843791920 to your computer and use it in GitHub Desktop.
Save petitJAM/62141534a0b672bc4526234843791920 to your computer and use it in GitHub Desktop.
Kotlin `let` `else`
val foobar: Foobar? = ...
foobar?.let { /* foobar is not null */ } ?: run { /* foobar is null */ }
// this might be cool except for the back ticks `
fun <T, R> T.`else`(block: T.() -> R) = run(block)
foobar?.let { /* foobar is not null */ } ?: `else` { /* foobar is null */ }
@petitJAM
Copy link
Author

this is stupid, don't do this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment