← Back to Kairo Docs|API Reference (Dokka)

Optional

sealed class Optional<out T : Any> : OptionalBase<T>

Kairo Optionals can be used to differentiate between missing and null values. This comes in especially handy for RFC 7396 (JSON Merge Patch).

Inheritors

Types

Link copied to clipboard
object Companion
Link copied to clipboard
data object Missing : Optional<Nothing>

The value was absent from the JSON. Treat as "do not modify".

Link copied to clipboard
data object Null : Optional<Nothing>

The value was explicitly set to null in the JSON. Treat as "clear this field".

Link copied to clipboard
data class Value<T : Any>(val value: T) : Optional<T>

The value was present and non-null in the JSON.

Properties

Link copied to clipboard
abstract val isSpecified: Boolean

Functions

Link copied to clipboard
abstract fun getOrThrow(): T?
Link copied to clipboard
fun <T : Any> Optional<T>.ifSpecified(block: (T?) -> Unit)

Runs block for Optional.Null and Optional.Value, skips Optional.Missing. The block receives null for the Null variant.

Link copied to clipboard
fun <T : Any, R : Any> Optional<T>.transform(block: (T?) -> R?): Optional<R>

Applies block to the inner value, preserving Optional.Missing state.