Extensions for java.util.Optional

JVM
JRE8
1.8

Any

Returns this Optional's value if present, or otherwise defaultValue.

fun <T> Optional<out T>.Any()
JVM
JRE8
1.8

asSequence

Returns a new sequence for this Optional's value if present, or otherwise an empty sequence.

fun <T : Any> Optional<out T>.asSequence(): Sequence<T>
JVM
JRE8
1.8

getOrNull

Returns this Optional's value if present, or otherwise null.

fun <T : Any> Optional<T>.getOrNull(): T?
JVM
JRE8
1.8

toCollection

Appends this Optional's value to the given destination collection if present.

fun <T : Any, C : MutableCollection<in T>> Optional<T>.toCollection(
    destination: C
): C
JVM
JRE8
1.8

toList

Returns a new read-only list of this Optional's value if present, or otherwise an empty list. The returned list is serializable (JVM).

fun <T : Any> Optional<out T>.toList(): List<T>
JVM
JRE8
1.8

toSet

Returns a new read-only set of this Optional's value if present, or otherwise an empty set. The returned set is serializable (JVM).

fun <T : Any> Optional<out T>.toSet(): Set<T>