Package-level declarations

Convenience extension functions for java.util.Optional to simplify Kotlin-Java interop.

Functions

Link copied to clipboard
fun <T : Any> Optional<out T>.asSequence(): Sequence<T>

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

Since Kotlin 1.8
Link copied to clipboard
fun <T> Optional<out T & Any>.getOrDefault(defaultValue: T): T

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

Since Kotlin 1.8
Link copied to clipboard
inline fun <T> Optional<out T & Any>.getOrElse(defaultValue: () -> T): T

Returns this Optional's value if present, or otherwise the result of the defaultValue function.

Since Kotlin 1.8
Link copied to clipboard
fun <T : Any> Optional<T>.getOrNull(): T?

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

Since Kotlin 1.8
Link copied to clipboard
fun <T : Any, C : MutableCollection<in T>> Optional<T>.toCollection(destination: C): C

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

Since Kotlin 1.8
Link copied to clipboard
fun <T : Any> Optional<out T>.toList(): List<T>

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

Since Kotlin 1.8
Link copied to clipboard
fun <T : Any> Optional<out T>.toSet(): Set<T>

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

Since Kotlin 1.8