Creates a Failure result from a given error. Automatically wraps the error in a Promise if it is asynchronous.
Promise
The type of the error to wrap.
A Result or ResultAsync depending on whether the input is a promise.
import { Result } from '@praha/byethrow';const result = Result.fail('Something went wrong');// Result.Result<never, string> Copy
import { Result } from '@praha/byethrow';const result = Result.fail('Something went wrong');// Result.Result<never, string>
import { Result } from '@praha/byethrow';const result = Result.fail(Promise.resolve('Async error'));// Result.ResultAsync<never, string> Copy
import { Result } from '@praha/byethrow';const result = Result.fail(Promise.resolve('Async error'));// Result.ResultAsync<never, string>
import { Result } from '@praha/byethrow';const result = Result.fail();// Result.Result<never, void> Copy
import { Result } from '@praha/byethrow';const result = Result.fail();// Result.Result<never, void>
combine - For combining multiple Results into a single Result.
Creates a Failure result from a given error. Automatically wraps the error in a
Promise
if it is asynchronous.Type Param: E
The type of the error to wrap.
Returns
A Result or ResultAsync depending on whether the input is a promise.
Example: Synchronous Usage
Example: Asynchronous Usage
Example: With No Value
See
combine - For combining multiple Results into a single Result.