concept Some in category kotlin

appears as: Some, Some
Functional Programming with Kotlin

This is an excerpt from Manning's book Functional Programming with Kotlin.

  • defined, in which case it will be a Some
  • The Joy of Kotlin

    This is an excerpt from Manning's book The Joy of Kotlin.

    This example prints nothing and will directly throw an exception because Kotlin is a strict language. Function parameters are evaluated before the function is executed, whether they’re needed or not. This means the getOrElse function parameter is evaluated in any case, whether it’s called on a Some or a None. The fact that the function parameter isn’t needed for a Some is irrelevant. This makes no difference when the parameter is a literal, but it makes a huge difference when it’s a function call. The getDefault function will be called in any case, so the first line will throw an exception and nothing will be displayed. This is generally not what you want.