error
Handy alias to create an EitherLeft with the info fixed to "error". Useful to signal a generic error without manually providing the info.
TIP
error is equivalent to left("error", value). To understand the full mechanics (custom info, pattern matching), see the left page.
Interactive example
Syntax
typescript
function error<
const GenericInput extends unknown
>(
input: GenericInput
): EitherError<GenericInput>Parameters
input: Data to attach to the error (message, object, context...)
Return value
An EitherLeft<"error", GenericInput> that you can consume with E.isLeft, E.whenHasInformation, or E.hasInformation(result, "error").
Use cases
- Signal a generic error when you do not need specialized information.
- Harmonize your returns with
E.successwhen there is only one type of success.
