Optional

sealed class Optional<out V>

A sealed class that can either be Present or Absent

It provides a convenient way to distinguish the case when a value is provided explicitly and should be serialized (even if it's null) and the case where it's absent and shouldn't be serialized.

Inheritors

Types

Link copied to clipboard
Link copied to clipboard
object Companion
Link copied to clipboard
data class Present<V>(val value: V) : Optional<V>

Functions

Link copied to clipboard
fun <V> Optional<V>.getOrElse(fallback: V): V

Returns the value if this Optional is Present or fallback else.

Link copied to clipboard
fun getOrNull(): V?

Returns the value if this Optional is Present or null else.

Link copied to clipboard
fun getOrThrow(): V

Returns the value if this Optional is Present or throws MissingValueException else.

Link copied to clipboard
fun <V, R> Optional<V>.map(mapper: (V) -> R): Optional<R>