/** * Represents the result of an operation that can either be successful or fail with an error. * @template T The type of the value returned on success. */ export declare class Result { value: T | undefined; error: Error | undefined; /** * Creates a successful result with the specified value. * @template T The type of the value. * @param {T} value The value to be wrapped in the successful result. * @returns {Result} A successful result containing the value. */ static success(value: T): Result; /** * Creates a failure result with the specified error. * @template T The type of the value. * @param {Error} error The error to be wrapped in the failure result. * @returns {Result} A failure result containing the error. */ static failure(error: Error): Result; /** * Constructs a new instance of the Result class. * @param {T | undefined} value The value associated with the result, if successful. * @param {Error | undefined} error The error associated with the result, if failed. * @throws {Error} If both value and error are provided. */ private constructor(); /** * Checks if the result is successful. * @returns {this is { value: T }} True if the result is successful, false otherwise. */ isSuccess(): this is { value: T; }; /** * Checks if the result is a failure. * @returns {this is { error: Error }} True if the result is a failure, false otherwise. */ isFailure(): this is { error: Error; }; /** * Returns the value if the result is successful, or throws the error if it is a failure. * @returns {T} The value, if the result is successful. * @throws {Error} The error, if the result is a failure. */ getOrThrow(): T; /** * Returns the value if the result is successful, or the specified default value if it is a failure. * * @param {T} defaultValue - The default value to return if the result is a failure. * @returns {T} The value if the result is successful, or the default value if it is a failure. */ getOrDefault(defaultValue: T): T; /** * Returns the value if the result is successful, or the result of the transfer function if it is a failure. * @param {(error: Error) => T} transfer A function that transfers the error to a value. * @returns {T} The value, if the result is successful, or the result of the transfer function if it is a failure. */ getOrElse(transfer: (error: Error) => T): T; /** * Executes the specified function if the result is successful. * @param {(value: T) => void} f A function to be executed if the result is successful. * @returns {Result} The current result instance. */ onSuccess(f: (value: T) => void): Result; /** * Executes the specified function if the result is a failure. * @param {(error: Error) => void} f A function to be executed if the result is a failure. * @returns {Result} The current result instance. */ onFailure(f: (error: Error) => void): Result; /** * Recovers from a failure by applying the specified transform function. * @param {(error: Error) => T} transform A function that transforms the error to a value. * @returns {Result} A new successful result with the transformed value if the current result is a failure, or the current result if it is already successful. */ recover(transform: (error: Error) => T): Result; /** * Recovers from a failure by applying the specified asynchronous transform function. * @param {(error: Error) => Promise} transform An asynchronous function that transforms the error to a value. * @returns {Promise>} A promise that resolves to a new successful result with the transformed value if the current result is a failure, or the current result if it is already successful. */ recoverAsync(transform: (error: Error) => Promise): Promise>; } /** * Executes the specified function and wraps the result in a Result instance. * @template T The type of the value returned by the function. * @template A The type of the arguments passed to the function. * @param {(...args: A) => T} f The function to be executed. * @param {...A} args The arguments to be passed to the function. * @returns {Result} A result containing the value returned by the function if it succeeds, or a failure result if an error occurs. */ export declare const runCatching: (f: (...args: A) => T, ...args: A) => Result; /** * Executes the specified asynchronous function and wraps the result in a Promise of a Result instance. * @template T The type of the value returned by the asynchronous function. * @template A The type of the arguments passed to the asynchronous function. * @param {(...args: A) => Promise} f The asynchronous function to be executed. * @param {...A} args The arguments to be passed to the asynchronous function. * @returns {Promise>} A promise that resolves to a result containing the value returned by the asynchronous function if it succeeds, or a failure result if an error occurs. */ export declare const runAsyncCatching: (f: (...args: A) => Promise, ...args: A) => Promise>;