OptionalValue

interface OptionalValue<T : Any?>


isPresent should be set to true if value != null when value == null it MAY be set to true, which will cause a literal null to be sent to underlying storage when isPresent == false no value will be sent to underlying storage e.g. if(v.isPresent) store.put("key", v.valueOrThrow())

Summary

Public companion functions

OptionalValue<T>
<T : Any?> absent()
OptionalValue<T?>
<T : Any?> ofNullable(value: T?)

return a present() or presentNull depending on if value is null or not

OptionalValue<T>
<T : Any?> present(value: T)
OptionalValue<T?>
<T : Any?> presentNull()

Public functions

open T
defaultIfNotPresent(defaultValue: T)

Return the value if present and if not, return a user-provided default.

Unit
doWhenPresent(fn: (T) -> Unit)
open T?

Get back null if the value isn't present, else, the value.

OptionalValue<O>
<O : Any?> map(fn: (T) -> O)

perform a map operation, only applied for present values convenience to alleviate presence or nullability checks to perform transforms

Public properties

Boolean
T

Public companion functions

absent

fun <T : Any?> absent(): OptionalValue<T>

ofNullable

fun <T : Any?> ofNullable(value: T?): OptionalValue<T?>

return a present() or presentNull depending on if value is null or not

present

fun <T : Any?> present(value: T): OptionalValue<T>

presentNull

fun <T : Any?> presentNull(): OptionalValue<T?>

Public functions

defaultIfNotPresent

open fun defaultIfNotPresent(defaultValue: T): T

Return the value if present and if not, return a user-provided default.

doWhenPresent

fun doWhenPresent(fn: (T) -> Unit): Unit

getOrNull

open fun getOrNull(): T?

Get back null if the value isn't present, else, the value.

map

fun <O : Any?> map(fn: (T) -> O): OptionalValue<O>

perform a map operation, only applied for present values convenience to alleviate presence or nullability checks to perform transforms

Public properties

isPresent

val isPresentBoolean

value

val value: T