If a value is present, returns the result of applying the given Optional-bearing mapping function to the value, otherwise returns an empty Optional.
Essentially, use [[map]] if you're returning an Object and flatMap
if you're returning an Optional.
If a value is present, returns an Optional describing (as if by [[Optional.ofNullable]]) the result of applying the given mapping function to the value, otherwise returns an empty Optional.
If you're familiar with JavaScript, you know that Array.prototype.map()
works like a factory. You supply it with an input set, it applies the same process to each item, then it outputs them as an array.
Optional.map()
is the same concept, except instead of taking and returning arrays, it takes and returns single items.
If a value is present, returns the value, otherwise throws NoSuchElementException.
If a value is present, returns the value, otherwise throws an exception produced by the exception supplying function.
Static
emptyStatic
ofStatic
ofGenerated using TypeDoc
A container object which may or may not contain a non-null value. If a value is present, isPresent() returns true. If no value is present, the object is considered empty and isPresent() returns false.
See
async-optional
for a JavaScript implementation of Java Optional.See java.util.Optional for full documentation