Creates an iterator which yields an item if this optional has an item; otherwise iterator yields no items.
Creates an optional resolving to original item if this optional has an item and predicate
evaluates
to true
for it, or resolving to empty otherwise.
A predicate to evaluate an item
Creates an optional with the following behavior:
mapper
to it, and tries to retrieve the first item from
the returned iterable. If there's an item, resolves to it, otherwise resolves to empty.Function which takes an item and returns an iterable to create an optional from.
Creates a stream with the following behavior:
mapper
to it, and uses a returned iterable as an input of the
created stream.Function which takes an item and returns an iterable to create new stream from.
If this optional has an item, returns that item, otherwise throws an error.
Returns true
if this optional has an item and predicate
evaluates to true
for it; false
otherwise.
The predicate to test an item
Returns true
if this optional has an item and predicate
evaluates to false
for it, or if this optional
is empty. False otherwise.
The predicate to test an item
Returns true
if this optional has an item and it strict-equals (===
) the passed item
. False otherwise.
An item to test an item
Returns true
if this optional has an item, false otherwise
Returns an optional with the following behavior:
mapper
passing this item as an argument, and resolves to
the value returned by mapper
The function to transform an item with
Returns an optional with the following behavior:
mapper
passing this item as an argument; if mapper
returns
null
or undefined
resolves to empty; otherwise resolves to the value returned by mapper
The function to transform an item with
If this optional has an item returns this item; otherwise returns other
Value to return if this optional is empty
If this optional has an item returns this item; otherwise returns value returned by get
.
Function to take result from if this optional is empty
If this optional has an item returns this item; otherwise returns null
If this optional has an item returns this item; otherwise throws an error created by createError
Function to create error if this optional is empty
If this optional has an item returns this item; otherwise returns undefined
Returns {has: true, val: item}
if this optional contains an item, {has: false}
otherwise
If this optional has an item returns an array containing that item as the only element, otherwise returns an empty array
Creates a stream with an item provided by this optional if it has an item; otherwise the new stream is empty.
Generated using TypeDoc
An optional is just like Stream but contains no more than one item. All stream properties (laziness, statelessness) fully apply to optionals.
Like stream, optional has intermediate and terminal operations. When a terminal operation is executed, the result value is computed — this process is described as “an optional resolves to a value” if there is an item, or “an optional resolves to empty” if there's no one.