Result allows you to show to a consumer that a function might throw and force them to handle it.
T Value type
E Error type
Usage
function functionThatMightFail(): Result<T, E>;
Examples
const functionThatMightFail = (): Result<string, string> => Ok("Hello, World!"); const result = functionThatMightFail(); console.log(result.unwrap()); // "Hello, World!"
Tries to return error value if value is Ok throws custom error message
Maps Result<T, E> to Result<A, E> using the passed mapping function
Maps Result<T, E> to Result<T, A> using the passed mapping function
In the Err case returns the mapped value using the function else returns defaultVal
mapErrOrElse<A>(): A
In the Err case returns the mapped value using the function else returns value of def
In the Ok case returns the mapped value using the function else returns defaultVal
In the Ok case returns the mapped value using fn else returns value of def
Allows you to run callbacks based on the result.
unwrapErrOr(defaultVal: E): E
Tries to unwrap the error if vale is Ok returns defaultVal
unwrapErrOrElse(fn: (val: T) => E): E
Tries to return the error if value is Ok calls fn
unwrapOrElse(fn: (err: E) => T): T
Tries to return the value if value is Err calls fn