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)
| 140 | * @throws NullPointerException if the mapping function is null |
| 141 | */ |
| 142 | public<U> Optional<U> map(Function<? super T, ? extends U> mapper) { |
| 143 | Objects.requireNonNull(mapper); |
| 144 | if (!isPresent()) |
| 145 | return Optional.empty(); |
| 146 | else { |
| 147 | return Optional.ofNullable(mapper.apply(getValue())); |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | /** |
| 152 | * If a value is present, apply the provided {@code Optional}-bearing |
no test coverage detected