If a mod object is present, apply the provided mapping function to it, and if the result is non-null, return an Optional describing the result. Otherwise return an empty Optional. @apiNote This method supports post-processing on optional values, without the need to explicitly check
(Function<? super T, ? extends U> mapper)
| 192 | * @throws NullPointerException if the mapping function is null |
| 193 | */ |
| 194 | public<U> Optional<U> map(Function<? super T, ? extends U> mapper) { |
| 195 | Objects.requireNonNull(mapper); |
| 196 | if (!isPresent()) |
| 197 | return Optional.empty(); |
| 198 | else { |
| 199 | return Optional.ofNullable(mapper.apply(get())); |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | /** |
| 204 | * If a value is present, apply the provided {@code Optional}-bearing |