or

open fun <T> or(suppliers: Array<Supplier<Optional<T>>>): Optional<T>(source)

Returns the first present Optional from the given suppliers.

Emulates Java 9+ Optional.or() chaining with varargs support:


// Java 9+
Optional<T> result = opt1.or(() -> opt2).or(() -> opt3);

// Java 8 with Optionals
Optional<T> result = Optionals.or(() -> opt1, () -> opt2, () -> opt3);

Suppliers are evaluated lazily with short-circuit evaluation.

Return

the first present Optional, or empty if all are empty

Parameters

<T>

the type of the value

suppliers

suppliers of Optionals to evaluate in order