import type { Err, ExtractErrTypes, ExtractOkTypes, Ok, Result } from './types'; /** * Creates a successful Result */ export declare function ok(value: T): Result; /** * Creates a failed Result */ export declare function err(error: E): Result; /** * Wraps a function that might throw into a Result */ export declare function tryCatch(fn: () => T, errorHandler?: (error: unknown) => E): Result; /** * Wraps an async function that might throw into a ResultAsync */ export declare function tryCatchAsync(fn: () => Promise, errorHandler?: (error: unknown) => E): Promise, E>>; /** * Combines multiple Results into a single Result containing an array of values * Short-circuits on the first error */ export declare function combine[]>(results: T): Result, ExtractErrTypes>; /** * Combines multiple Results, collecting all errors if any fail */ export declare function combineWithAllErrors[]>(results: T): Result, ExtractErrTypes[]>; /** * Helper to convert a nullable value into a Result */ export declare function fromNullable(value: T | null | undefined, error: E): Result, E>; /** * Helper to convert a Promise into a ResultAsync */ export declare function fromPromise(promise: Promise, errorHandler?: (error: unknown) => E): Promise, E>>; /** * Type guard to check if a value is a Result */ export declare function isResult(value: unknown): value is Result; /** * Sequences an array of async Result operations, stopping at the first error */ export declare function sequence(operations: (() => Promise>)[]): Promise>; /** * Executes async Result operations in parallel */ export declare function parallel(operations: (() => Promise>)[]): Promise>; /** * Maps over an array with a Result-returning function */ export declare function traverse(items: T[], fn: (item: T) => Result): Result; /** * Async version of traverse */ export declare function traverseAsync(items: T[], fn: (item: T) => Promise>): Promise>; /** * Flattens a nested Result, E> into Result */ export declare function flatten(result: Result, E>): Result; /** * Taps into a Result without modifying it - useful for logging/debugging */ export declare function tap(result: Result, onOk?: (value: T) => void, onErr?: (error: E) => void): Result; /** * Swaps Ok and Err - useful for inverting logic */ export declare function swap(result: Result): Result; /** * Filters a Result based on a predicate */ export declare function filter(result: Result, predicate: (value: T) => boolean, error: E): Result; /** * Returns Ok value or throws error - useful at boundaries */ export declare function unwrapOrThrow(result: Result, mapError?: (error: E) => Error): T; /** * Converts Result to Promise - Ok becomes resolved, Err becomes rejected */ export declare function toPromise(result: Result, mapError?: (error: E) => Error): Promise; /** * Gets the Ok value or a default computed lazily */ export declare function getOrElse(result: Result, fn: (error: E) => T): T; /** * Collects multiple Results, returning Ok with all values or Err with first error */ export declare function all(results: Result[]): Result; /** * Returns the first Ok result, or the last Err if all fail */ export declare function any(results: Result[]): Result; /** * Partitions an array of Results into [successes, failures] */ export declare function partition(results: Result[]): [T[], E[]]; // Ok implementation declare class OkImpl implements Ok { readonly isOk: unknown; readonly isErr: unknown; readonly _tag: unknown; readonly value: T; constructor(value: T); map(fn: (value: T) => U): Result; mapErr(_fn: (error: E) => F): Result; andThen(fn: (value: T) => Result): Result; orElse(_fn: (error: E) => Result): Result; match(patterns: { ok: (value: T) => U, err: (error: E) => U }): U; unwrap(): T; unwrapOr(_defaultValue: T): T; unwrapOrElse(_fn: (error: E) => T): T; expect(_msg: string): T; } // Err implementation declare class ErrImpl implements Err { readonly isOk: unknown; readonly isErr: unknown; readonly _tag: unknown; readonly error: E; constructor(error: E); map(_fn: (value: T) => U): Result; mapErr(fn: (error: E) => F): Result; andThen(_fn: (value: T) => Result): Result; orElse(fn: (error: E) => Result): Result; match(patterns: { ok: (value: T) => U, err: (error: E) => U }): U; unwrap(): never; unwrapOr(defaultValue: T): T; unwrapOrElse(fn: (error: E) => T): T; expect(msg: string): never; }