Takes a function which takes the value contained in this
and returns a
new Result; calls it and returns the result if this
is Ok
,
otherwise returns this
. Also sometimes known in other languages or
libraries as flatmap
or bind
.
the type contained in the Result returned by fn
the result of calling fn
if this
is Ok
, this
otherwise
Takes a function which takes the value contained in this
and returns a
promise which resolves to a new Result; calls it and returns the
result if this
is Ok
, otherwise returns a promise which resolves to
this
. This is an async version of andThen.
the type contained in the Result returned by fn
the result of calling fn
if this
is Ok
, this
otherwise
Takes a function which takes an error and returns a promise which resolves
to a new Result; calls it with the contained error and returns the
result if this
is Err
, otherwise returns a promise which resolves to
this
.
the result of calling fn
if this
is Err
, this
otherwise
Static
ErrStatic
OkStatic
wrapTakes a function that could be throw and converts it into an Result.
the type contained by the Result
Ok
with the return value of fn
if fn
doesn't throw,
otherwise Err
containing an Option which is None
if the
exception is null
or undefined
, and is Some
with the exception
otherwise
Static
wrapTakes a promise that could reject and converts it into an Result.
the type contained by the Result
the promise to convert
a Promise containing Ok
with the value resolved by promise
if
promise
doesn't reject, otherwise Err
containing an Option
which is None
if promise
rejects with a null
or undefined
, and is
Some
with the rejection value otherwise
Takes two functions, one is called with the contained value if this
is
Ok
and the other is called with the error if this
is Err
.
an object containing matcher functions
the return value of the Ok
or Err
matcher function
If this
is Err
, returns Option.Some containing the value in
this
. Otherwise return Option.None.
Option.Some with the value in this
if this
is Err
,
Option.None otherwise
If this
is Ok
, returns Option.Some containing the value in
this
. Otherwise return Option.None.
Option.Some with the value in this
if this
is Ok
,
Option.None otherwise
the type of the value contained in the Option
contained in this
if this
is Err
, returns Option.Some containing this
;
if this
is Ok
and the Option in this
is Option.None,
returns Option.None; otherwise returns Option.Some
containing Ok
containing the value in the Option in this
Transforms Result<T, E>
to Result<U, E>
by applying the provided
function to the contained value of Ok
and leaving Err
values unchanged.
this
if this
is Err
, otherwise Ok
containing the result of
applying fn
to the value in this
Transforms Result<T, E>
to Promise<Result<U, E>>
by applying the
provided async function to the contained value of Ok
and resolving Err
values unchanged.
a promise resolving to this
if this
is Err
, otherwise a
promise resolving to Ok
containing the value resolved by the promise
returned from applying fn
to the value in this
Transforms Result<T, E>
to Result<T, F>
by applying the provided
function to the contained value of Err
and leaving Ok
values unchanged.
this
if this
is Ok
, otherwise Err
containing the result of
applying fn
to the value in this
Transforms Result<T, E>
to Promise<Result<T, F>>
by applying the
provided async function to the contained value of Err
and resolving Ok
values unchanged.
a promise resolving to this
if this
is Ok
, otherwise a
promise resolving to Err
containing the value resolved by the promise
returned from applying fn
to the value in this
Static
collectTakes an Array of Result values. If any of the Result
values in the array is Err
, returns that Err
. Otherwise, returns Ok
containing an Array of each value inside each Result in the
original list.
Ok
containing an Array of values contained by each Result in the original Array if all Result values in the original
list are Ok
, otherwise returns the first Err
in the Array
A type which represents values that may encode either a successful result or an error result.