/** * Result utility pattern for better error handling * Provides a functional approach to error handling without exceptions */ /** * Base Result interface for operations that may succeed or fail */ export interface Result { readonly success: boolean; readonly data?: T; readonly error?: E; isOk(): this is Ok; isErr(): this is Err; unwrap(): T; unwrapOr(defaultValue: T): T; map(fn: (value: T) => U): Result; flatMap(fn: (value: T) => Result): Result; mapError(fn: (error: E) => F): Result; } /** * Success result */ export declare class Ok implements Result { readonly success = true; readonly data: T; constructor(data: T); map(fn: (value: T) => U): Result; flatMap(fn: (value: T) => Result): Result; mapError(_fn: (error: never) => F): Result; unwrap(): T; unwrapOr(_defaultValue: T): T; isOk(): this is Ok; isErr(): this is Err; } /** * Error result */ export declare class Err implements Result { readonly success = false; readonly error: E; constructor(error: E); map(_fn: (value: never) => U): Result; flatMap(_fn: (value: never) => Result): Result; mapError(fn: (error: E) => F): Result; unwrap(): never; unwrapOr(defaultValue: T): T; isOk(): this is Ok; isErr(): this is Err; } /** * Create a successful result */ export declare function ok(data: T): Ok; /** * Create an error result */ export declare function err(error: E): Err; /** * Wrap a potentially throwing function in a Result */ export declare function tryCatch(fn: () => T): Result; /** * Wrap an async potentially throwing function in a Result */ export declare function tryAsync(fn: () => Promise): Promise>; /** * Combine multiple results into a single result * Returns Ok with array of all values if all are Ok, otherwise returns first Err */ export declare function combine(results: Result[]): Result; /** * Sequence async results, stopping at the first error */ export declare function sequenceAsync(promises: Promise>[]): Promise>; /** * Apply a function to each element and collect results */ export declare function traverse(items: T[], fn: (item: T) => Result): Result; /** * Apply an async function to each element and collect results */ export declare function traverseAsync(items: T[], fn: (item: T) => Promise>): Promise>; /** * Partition results into successes and failures */ export declare function partition(results: Result[]): { successes: T[]; failures: E[]; }; /** * Type guard for Ok results */ export declare function isOk(result: Result): result is Ok; /** * Type guard for Err results */ export declare function isErr(result: Result): result is Err; /** * Convert a nullable value to a Result */ export declare function fromNullable(value: T | null | undefined, error?: Error): Result; /** * Convert a boolean to a Result */ export declare function fromBoolean(condition: boolean, error?: Error): Result; //# sourceMappingURL=result.d.ts.map