Re-exports core Result-handling utilities under two convenient namespaces:
Result
: Verbose and explicit usageR
: Shorthand alias for more concise codeType Alias | Description |
---|---|
Failure | Represents a failed result. |
Result | A union type representing either a success or a failure. |
ResultAsync | An asynchronous variant of Result, wrapped in a Promise . |
ResultFor | Resolves to the appropriate Result type (sync or async) based on the input type. |
ResultMaybeAsync | A result that may be either synchronous or asynchronous. |
Success | Represents a successful result. |
Type Alias | Description |
---|---|
InferFailure | Infers the Failure value type E from a Result or a function returning a Result. |
InferSuccess | Infers the Success value type T from a Result or a function returning a Result. |
Function | Description |
---|---|
do | Alias for succeed({}) . Commonly used as a neutral base value in functional chains or monadic pipelines. |
fail | Creates a Failure result from a given error. Automatically wraps the error in a Promise if it is asynchronous. |
succeed | Creates a Success result from a given value. Automatically wraps the value in a Promise if it is asynchronous. |
try | Wraps a function execution (sync or async) or a Promise in a Result or ResultAsync type, capturing errors and returning them in a structured way. |
Function | Description |
---|---|
andThen | Chains the next computation using the success value of a Result or ResultAsync. If the original result is a Failure, it is returned unchanged. Otherwise, the provided function is called, and its result is returned as-is. |
andThrough | Runs an additional computation using the success value of a Result or ResultAsync, but returns the original result if the additional computation is successful. |
bind | Chains another Result-producing computation and merges its success value into the existing object under the specified key. |
inspect | Executes a side effect function on the success value of a Result or ResultAsync, without modifying the original result. This is useful for debugging, logging, or performing other side effects while maintaining the original value and error state. |
inspectError | Executes a side effect function on the error value of a Result or ResultAsync, without modifying the original result. This is useful for debugging, logging, or performing other side effects while maintaining the original value and error state. |
map | Applies a transformation function to the success value of a Result or ResultAsync. If the input is a Failure, it will be returned unchanged. |
mapError | Applies a transformation function to the error value of a Result or ResultAsync. If the input is a Success, it will be returned unchanged. |
orElse | Chains the next computation using the error value of a Result or ResultAsync. If the original result is a Success, it is returned unchanged. Otherwise, the provided function is called, and its result is returned as-is. |
Function | Description |
---|---|
unwrap | Extracts the success value from a Result or ResultAsync. |
unwrapError | Extracts the error value from a Result or ResultAsync. |
Function | Description |
---|---|
assertFailure | Asserts that a Result or ResultAsync is a Failure and returns it. If the result is a Success, throws an error. |
assertSuccess | Asserts that a Result or ResultAsync is a Success and returns it. If the result is a Failure, throws an error. |
Function | Description |
---|---|
isFailure | Type guard to check if a Result is a Failure. |
isResult | Type guard to check if a value is a Result. |
isSuccess | Type guard to check if a Result is a Success. |
Function | Description |
---|---|
combine | Combines multiple Result or ResultAsync values into a single result. If all inputs are Success, returns a Success with combined values. If any input is a Failure, returns a Failure with an array of all errors. |
parse | Parses a value using a Standard Schema compatible schema. Returns a Result with the parsed value on success or validation errors on failure. |
pipe | Applies a sequence of functions to a value, from left to right. |