Ok type
Method to combine two results, if the first result is true return the second result, otherwise return the first result
compare value
Method to compare two results
other result to compare
true if results are equal
Inspect the result value if Ok
function to inspect the value
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.
function to check 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 error value to a new value if Err
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
Method to combine two results, if the first result is false use the error to build a new result, otherwise return the first result
Method to combine two results, if the first result is false use the error to build a new result from Promise, otherwise return the first result
Method to unwrap the value or throw an error.
Note: Error argument/callback was removed in favor of the .errMap((e) => new Error(e.message)).unwrap()
method.
Method to unwrap the value or if error return the default value
Method to unwrap the value or if error return default value from function
Method to unwrap the value or if error return default value from constructors valueOf
Result Ok instance.
Note: this class should not be used directly, use Ok function instead
Since
v1.0.0