Extensions for java.util.Optional

JVM
JRE8
1.7

asSequence

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

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

getOrNull

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

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

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.7

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.7

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>