data class Optional<T> : Any

A container object which optionally contains a value of type T.

Constructors

<init>

constructor(value: T?)

A container object which optionally contains a value of type T.

Parameters

Name Description
value: T?

if null, the container is considered empty

Methods

equalsValue

infix fun equalsValue(otherValue: T): Boolean

Returns true, if the value of this equals the otherValue. If no value isPresent, false is returned.

Parameters

Name Description
otherValue: T

ReturnValue

Name Description
Boolean

isEmpty

fun isEmpty(): Boolean

Returns true, if no value is present.

ReturnValue

Name Description
Boolean

isPresent

fun isPresent(): Boolean

Returns true, if a value is present.

ReturnValue

Name Description
Boolean

getOrNull

fun getOrNull(): T?

Returns a value, if available; otherwise null is returned.

ReturnValue

Name Description
T?

getResult

fun getResult(): Result<T, IllegalStateException>

Returns Result.success of the value, if available; otherwise Result.error is returned.

ReturnValue

Name Description
Result<T, IllegalStateException>

toString

fun toString(): String

ReturnValue

Name Description
String

toList

fun toList(): List<T>

ReturnValue

Name Description
List<T>

Extensions

map

inline fun <T, R> Optional<T>.map(transform: (T)->R): Optional<R>

Receiver

Name Description
Optional<T>

Parameters

Name Description
transform: (T)->R

ReturnValue

Name Description
Optional<R>

getOrElse

fun <T> Optional<T>.getOrElse(defaultValue: T): T

Receiver

Name Description
Optional<T>

Parameters

Name Description
defaultValue: T

ReturnValue

Name Description
T

CompanionObject

Optional

data class Optional<T> : Any

A container object which optionally contains a value of type T.

Methods

empty

fun <T> empty(): Optional<T>

ReturnValue

Name Description
Optional<T>