Takes a function which takes the value contained in this
and returns a
new Option; calls it and returns the result if this
is Some
,
otherwise returns None
. Also sometimes known in other languages or
libraries as flatmap
or bind
.
the type contained in the Option returned by fn
the result of calling fn
if this
is Some
, None
otherwise
Takes a function which takes the value contained in this
and returns a
promise which resolves to a new Option; calls it and returns the
result if this
is Some
, otherwise returns a promise which resolves to
None
. This is an async version of andThen.
the type contained in the Option returned by fn
the result of calling fn
if this
is Some
, None
otherwise
Takes a function that returns a promise which resolves to a new Option; calls it and returns the result if this
is None
, otherwise
returns a promise which resolves to this
.
the result of calling fn
if this
is None
, this
otherwise
Static
NoneStatic
SomeStatic
wrapTakes a value that could be null
or undefined
and converts it into an
Option.
the type contained by the Option values
the nullable value
None
if value
is null
or undefined
, Some
containing
value
otherwise
Takes two functions, one is called with the contained value if this
is
Some
and the other is called if this
is None
.
the return value of the Some
or None
matcher function
If this
is a Some
, return an Result.Ok with the contained
value. Otherwise, return an Result.Err containing the passed
default error value.
the type of error
(and the error type of the returned
Result)
Result.Ok containing the value in this
if this
is
Some
, otherwise Result.Err containing error
If this
is a Some
, return an Result.Ok with the contained
value. Otherwise, return an Result.Err with the value returned by
calling the passed function.
the return type of fn
(and the error type of the returned
Result)
Result.Ok containing the value in this
if this
is
Some
, otherwise Result.Err containing the value returned by
error
if this
is None
, returns Result.Ok containing None
;
if this
is Some
and the Result in this
is Result.Err,
returns the Result.Err; otherwise returns Result.Ok
containing Some
containing the value in the Result in this
If this
is None
, returns None
. Otherwise, calls the predicate on the
value contained in this
; if the predicate returns true
then this
is
returned, if the predicate returns false
then None
is returned.
None
if this
is None
or if fn
returns false
when applied
to the value in this
, this
otherwise
Transforms Option<T>
to Promise<Option<U>>
by applying the provided
async function to the contained value of Some
and resolving None
values
unchanged.
a promise resolving to None
if this
is None
, otherwise a
promise resolving to Some
containing the value resolved by the promise
returned from applying fn
to the value in this
Called on an Option containing a tuple -- if this
is Some
,
returns a tuple of Some
containing the contained values. Otherwise,
returns a tuple of None
.
a tuple of Some
containing the values in the tuple contained in
this
if this
is Some
, a tuple of None
otherwise
Takes another Option, if both Option values are Some
,
returns a Some
containing a tuple of the contained values. Otherwise
returns None
.
Some
containing a tuple with the values in this
and other
if
both this
and other
are Some
, None
otherwise
Static
collectTakes an Array of Option values. If any of the Option
values in the array is None
, returns None
. Otherwise, returns Some
containing an Array of each value inside each Option in the
original list.
the type contained by the Option values
Some
containing an Array of values contained by each Option in the original Array if all Option values in the original
list are Some
, None
otherwise
A type which represents values that may or may not be present, without using
undefined
ornull
.