error type
Method to combine two results, if the first result is true return the second result, otherwise return the first result
Method to combine two results, if the first result is true use the value to build a new result from Promise, otherwise return the error
Method to compare two results
other result to compare
true if results are equal
Inspect the result value if Err
function to inspect the error
this result instance
Returns true if the result is Err and callback function returns true for the value inside of Err.
true if the result is Err and the callback function returns true for the value inside of Err
Returns true if the result is Ok and callback function returns true for the value inside of Ok.
true if the result is Ok and the callback function returns true for the value inside of Ok
Map the result value to a new value if Ok
Map the error value to a new value if Err
function to map the error value
new error result instance with mapped error
const mapAsTypeErr = (err: Error): TypeError => new TypeError(`Mapped: ${err.message}`);
Err<Error>(new Error('broken')).mapErr(mapAsTypeErr) // Err<TypeError>(new TypeError('Mapped: broken'))
Ok<number>(2).mapErr(mapAsTypeErr); // Ok<number>(2)
// error mapping and logging example
const logErr = (err: Error) => console.error('Error:', err);
Err<Error>(new Error('broken')).mapErr(mapAsTypeErr).inspectErr(logErr);
Method to combine two results, if the first result is false return the second result, otherwise return the first result
compare value
Method to unwrap the value or if error return the default value
default value to return if error
Method to unwrap the value or if error return default value from function
function to return default value
Method to unwrap the value or if error return default value from constructors valueOf
constructor to return default value from valueOf
Result Err instance.
Note: this class should not be used directly, use Err function instead
Since
v1.0.0