Create an instance of Err
.
Note: While you may create the Result
type via normal
JavaScript class construction, it is not recommended for the functional
style for which the library is intended. Instead, use err
.
// Avoid:
const anErr = new Result.Err('alas, failure');
// Prefer:
const anErr = Result.err('alas, failure');
Create an instance of Err
.
Note: While you may create the Result
type via normal
JavaScript class construction, it is not recommended for the functional
style for which the library is intended. Instead, use err
.
// Avoid:
const anErr = new Result.Err('alas, failure');
// Prefer:
const anErr = Result.err('alas, failure');
The value to wrap in an Err
.
Create an instance of
Err
.If you need to create an instance with a specific type (as you do whenever you are not constructing immediately for a function return or as an argument to a function), you can use a type parameter:
Note: passing nothing, or passing
null
orundefined
explicitly, will produce aResult<T, Unit>
, rather than producing the nonsensical and in practice quite annoyingResult<null, string>
etc. SeeUnit
for more.In the context of an immediate function return, or an arrow function with a single expression value, you do not have to specify the types, so this can be quite convenient.
Template: T
The type of the item contained in the
Result
.Param: E
The error value to wrap in a
Result.Err
.