If a value is present, apply the provided Optional-bearing mapping function to it, return that result, otherwise return an empty Optional. This method is similar to #map(Function), but the provided mapper is one whose result is already an Optional, and if invoked, {@
(Function<? super T, Optional<U>> mapper)
| 166 | * a null result |
| 167 | */ |
| 168 | public<U> Optional<U> flatMap(Function<? super T, Optional<U>> mapper) { |
| 169 | Objects.requireNonNull(mapper); |
| 170 | if (!isPresent()) |
| 171 | return Optional.empty(); |
| 172 | else { |
| 173 | return Objects.requireNonNull(mapper.apply(getValue())); |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | /** |
| 178 | * Return the mod object if present, otherwise return {@code other}. |
no test coverage detected