Skip to content

Instantly share code, notes, and snippets.

@soudmaijer
Last active May 20, 2018 19:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soudmaijer/f66f5de8a2262b6c4fb83697a138f37b to your computer and use it in GitHub Desktop.
Save soudmaijer/f66f5de8a2262b6c4fb83697a138f37b to your computer and use it in GitHub Desktop.
val orderOrElse: Order = orderById?.apply {
// do stuff with order
} ?: Order() // orElse with default
val orderOrElseThrow: Order = orderById?.apply {
// do stuff with order
} ?: throw RuntimeException("orElseThrow") // orElseThrow
val orderId: Long? = orderById?.let {
// do stuff with order
it.id
} // Return something else than an Order
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment