Represents a failed result.
A union type representing either a success or a failure.
An asynchronous variant of Result, wrapped in a Promise
.
Resolves to the appropriate Result type (sync or async) based on the input type.
A result that may be either synchronous or asynchronous.
Represents a successful result.
Infers the Failure value type E
from a Result or a function returning a Result.
Infers the Success value type T
from a Result or a function returning a Result.
Alias for succeed({})
. Commonly used as a neutral base value in functional chains or monadic pipelines.
Creates a Failure result from a given error.
Automatically wraps the error in a Promise
if it is asynchronous.
Creates a Success result from a given value.
Automatically wraps the value in a Promise
if it is asynchronous.
Wraps a function execution (sync or async) in a Result or ResultAsync type, capturing errors and returning them in a structured way.
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.
Runs an additional computation using the success value of a Result or ResultAsync, but returns the original result if the additional computation is successful.
Chains another Result-producing computation and merges its success value into the existing object under the specified key.
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.
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.
Applies a transformation function to the success value of a Result or ResultAsync. If the input is a Failure, it will be returned unchanged.
Applies a transformation function to the error value of a Result or ResultAsync. If the input is a Success, it will be returned unchanged.
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.
Extracts the success value from a Result, ResultAsync.
Extracts the error value from a Result, ResultAsync.
Re-exports core Result-handling utilities under two convenient namespaces:
Result
: Verbose and explicit usageR
: Shorthand alias for more concise codeExample: Basic Usage
Example: Shorthand Usage