The following scenario has multiple Optionals, a real example could be where you are calling
multiple validation checks where each check returns an Optional<T>
. You then want to check
if each Optional contains a value or is empty - returning the first one that has a value. If none
contain a value (ie. are instances of Optional.empty
) then you return a default value.
In this example we are using Optional<Single>
where Single
is an RxJava Observer that returns
a single value.
import com.google.common.collect.ImmutableList;