public <U> Optional<U> flatMap (Function<? super T, ? extends Optional<? extends U>> mapper)

If a value is present, returns the result of applying the given Optional-bearing mapping function to the value, otherwise returns an empty Optional.

This method is similar to map(Function), but the mapping function is one whose result is already an Optional, and if invoked, flatMap does not wrap it within an additional Optional.

Parameters:
<U>    The type of value of the Optional returned by the mapping function
mapper    the mapping function to apply to a value, if present

Returns:  the result of applying an Optional-bearing mapping function to the value of this Optional, if a value is present, otherwise an empty Optional

Exceptions:
NullPointerException    if the mapping function is null or returns a null result