public < V > Optional < V > map ( final Function < T , V > function ) { checkNotNull ( function , "Must provide non null function to map" ) ; if ( isPresent ( ) ) { final V applied = function . apply ( get ( ) ) ; return applied == null ? Optional . < V > empty ( ) : Optional . of ( function . apply ( get ( ) ) ) ; } else { return Optional . empty ( ) ; } }
If a value is present map is with function and if the result is non - null return an Optional describing the result . Otherwise return an empty Optional .