Returns true if the optional has an item and the predicate evaluates to
true for it, or if the optional is empty.
true if the predicate evaluates to true or the optional is empty,
false otherwise.
Returns an optional resolving to the original item if this optional has an
item and the predicate evaluates to true for it, or resolving to empty
otherwise.
An optional containing the item if the predicate evaluates to true
for it.
Returns an optional with a possibly narrowed type. Resolves to the original
item if this optional contains an item and the predicate evaluates to true
for it; otherwise, resolves to empty. For example, this can be used to filter
out null values from the optional.
streamOf('a', null, 'b')
.head()
.filter<string>(item => typeof item === 'string')
.toArray() satisfies string[]
An Optional containing the item if the predicate is satisfied; otherwise, an empty optional.
Returns an optional with the following behavior:
Optionaldepth: DThe depth of flattening. Defaults to 1.
An Optional containing the first item of the flattened iterable.
Creates an optional with the following behavior:
mapper to it, and retrieves the
first item from the returned iterable. If there is an item, resolves to it;
otherwise, resolves to empty.An optional containing the first item of the iterable returned by
mapper, or empty if the iterable has no items or this optional is empty.
Creates a Stream with the following behavior:
mapper to it and uses the
returned iterable as input for the created stream.A stream created from the iterable returned by mapper, or an empty
stream if this optional is empty.
If this optional contains an item, invokes effect for it.
Returns an optional with the following behavior:
mapper with this item as an argument
and resolves to the value returned by mapper.An optional containing the result of applying mapper to the item,
or an empty optional if this optional is empty.
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.An optional containing the non-null and non-undefined result of applying
mapper to the item, or an empty optional otherwise
Returns an optional that resolves just like this optional, but when resolving
to an item, additionally executes effect on that item before yielding it.
One possible usage for this method is mutating the item in place.
The optional that resolves just like this one, but executes
effect on the item before it is yielded
Returns {has: true, val: item} if this optional contains an item, or {has: false}
otherwise. val? undefined only exists for type-safe destructuring; there won't
be a val if the optional is empty.
An object indicating whether the optional contains an item, and the item itself if present.
Returns true if this optional has an item and predicate evaluates to true for it;
false otherwise.
true if the optional has an item and the predicate returns true, otherwise false.
An Optional is similar to a Stream but contains no more than one item. All stream properties, such as laziness, statelessness and implementing the iteration protocol, fully apply to optionals.
Like streams, optionals support intermediate and terminal operations. When a terminal operation is executed, the result value is computed. This process is described as: