T The type of the value wrapped in the Ok
of the Result
.
U The type of the value wrapped in the Ok
of the Result
returned by the thenFn
.
E The type of the value wrapped in the Err
of the Result
.
Generated using TypeDoc
Apply a function to the wrapped value if
Ok
and return a newOk
containing the resulting value; or if it isErr
return it unmodified.This differs from
map
in thatthenFn
returns anotherResult
. You can useandThen
to combine two functions which both create aResult
from an unwrapped type.You may find the
.then
method on an ES6Promise
helpful for comparison: if you have aPromise
, you can pass itsthen
method a callback which returns anotherPromise
, and the result will not be a nested promise, but a singlePromise
. The difference is thatPromise#then
unwraps all layers to only ever return a singlePromise
value, whereasResult.andThen
will not unwrap nestedResult
s.This is is sometimes also known as
bind
, but not aliased as such becausebind
already means something in JavaScript.Examples