public <U> Optional<U> flatMap(Function<? super T, Optional<U>> mapper) {
        Objects.requireNonNull(mapper);
        if (!isPresent())
            return empty();
        else {
            return Objects.requireNonNull(mapper.apply(value));
        }
    }
If a value is present, apply the provided {@code Optional}-bearing
mapping function to it, return that result, otherwise return an empty
{@code Optional}.  This method is similar to {@link #map(Function)},
but the provided mapper is one whose result is already an {@code Optional},
and if invoked, {@code flatMap} does not wrap it with an additional
{@code Optional}.

@param <U>    The type parameter to the {@code Optional} returned by
@param mapper a mapping function to apply to the value, if present
              the mapping function
@return the result of applying an {@code Optional}-bearing mapping
function to the value of this {@code Optional}, if a value is present,
otherwise an empty {@code Optional}
@throws NullPointerException if the mapping function is null or returns
                             a null result
android/android_framework/base/src/main/java/github/tornaco/android/thanos/core/util/Optional.java