map

fun <U> map(mapper: (T?) -> U?): Optional<U?>

If a value is present, returns an Optional describing (as if by ofNullable) the result of applying the given mapping function to the value, otherwise returns an empty Optional.

If the mapping function returns a null result then this method returns an empty Optional.

Return

an Optional describing the result of applying a mapping function to the value of this Optional, if a value is present, otherwise an empty Optional

Parameters

mapper

the mapping function to apply to a value, if present

the type of the value returned from the mapping function