Creates an instance encapsulating the given value if it is non-null.
If the value is null, it returns an instance signifying the absence of any value.
This allows for the safe handling of values that might be null or undefined.
The value to evaluate and potentially encapsulate.
An instance representing either the presence of a non-null value or the absence of a value.
A TypeScript implementation inspired by Java's
Optional, designed as a container object that may or may not contain a non-null value. It offers methods for handling the value's presence or absence in a more expressive and safer way, aiming to reduce the chances of null pointer exceptions.Example
Example