import type { Result, AsyncResult, MaybeAsyncResult, ErrTypeOf, Collected, AsyncCollected, OkTypeOf, CollectedErr } from './types'; /** * Reduces an array of `Result` objects into a single `Result` by applying a reducer function. * * @param results - An array of `Result` objects. * @param reducer - A function that takes an accumulator, a result, an index, and the list of results, and returns the updated accumulator. * @param initial - The initial value of the accumulator. * @returns A `Result` object that represents the reduced value. * @template T - The type of the successful result. * @template S - The type of the accumulator. * @template E - The type of the error. */ export declare const reduce: (results: readonly Result[], reducer: (acc: S, result: T, index: number, list: readonly Result[]) => S, initial: S) => Result; /** * Reduces an array of `Result` objects by applying a reducer function to each error value. * If any of the `Result` objects is an `Ok` variant, it is returned as is. * If all `Result` objects are `Err` variants, the reducer function is applied to each error value * in the array, starting with the initial value, and the final result is wrapped in an `Err` variant. * * @param results - An array of `Result` objects. * @param reducer - A function that takes an accumulator and an error value, and returns the updated accumulator. * @param initial - The initial value of the accumulator. * @returns A `Result` object that is either an `Ok` variant if any of the `Result` objects is an `Ok` variant, * or an `Err` variant with the final result of applying the reducer function to each error value. * @template T - The type of the value in the `Ok` variant of the `Result` objects. * @template S - The type of the accumulator. * @template E - The type of the value in the `Err` variant of the `Result` objects. */ export declare const reduceErr: (results: readonly Result[], reducer: (acc: S, err: E) => S, initial: S) => Result; /** * Collects the results of an array of `Result` objects into a single `Result` object. * * @template R - The array type containing `Result` objects. * @param results - The array of `Result` objects to collect. * @returns A `Result` object containing the collected results. */ export declare const collect: []>(results: R) => Result, ErrTypeOf>; /** * Collects the error values from an array of `Result` objects. * * @template R - The array type containing `Result` objects. * @param results - The array of `Result` objects. * @returns A `Result` object containing the collected error values. */ export declare const collectErr: []>(results: R) => Result, CollectedErr>; /** * Collects the results of multiple asynchronous operations into a single result. * * @template R - The array type containing the results of the asynchronous operations. * @param results - An array of promises representing the asynchronous operations. * @returns A promise that resolves to the collected results or rejects with the error of the first failed operation. */ export declare const collectAsync: []>(results: R) => AsyncResult, ErrTypeOf>>; /** * Partitions an array into two separate arrays based on a given predicate. * The first array contains elements that satisfy the predicate, while the second array contains elements that do not. * * @param list - The array to be partitioned. * @param predicate - The predicate function used to determine whether an element should be included in the first array. * @returns An array containing two arrays: the first array contains elements that satisfy the predicate, and the second array contains elements that do not. */ export declare const partition: { (list: T[], predicate: (x: T) => boolean): [T[], T[]]; (list: T[], predicate: (x: T) => x is S): [S[], Exclude[]]; }; /** * Separates an array of `Result` objects into two separate `Result` objects. * The first `Result` contains the collected successful values, while the second `Result` contains the collected error values. * * @param results An array of `Result` objects. * @returns A tuple containing two `Result` objects: the first one contains the collected successful values, and the second one contains the collected error values. */ export declare const separate: []>(results: R) => [Result, never>, Result>]; /** * Collects a list of `Result` values into a single `Result`. * - If all inputs are `Ok`, returns `Ok` with the array of unwrapped values. * - If any inputs are `Err`, returns `Err` with the array of ALL error values. * * @param results An array of `Result` objects. * @returns `Ok` of collected values or `Err` of all error values. */ export declare const collectAll: []>(results: R) => Result, [ErrTypeOf] extends [never] ? never : ErrTypeOf[]>; /** * Executes an array of tasks that return `Result` objects and collects their successful results. * If any task returns an `Err` result, the function stops executing and returns that error. * * @param tasks An array of tasks that return `Result` objects. * @returns A `Result` object containing an array of successful results, or an error if any task fails. */ export declare const sequence: Result)[]>(tasks: T) => Result<{ -readonly [K in keyof T]: OkTypeOf>; }, ErrTypeOf>>; /** * Executes an array of asynchronous tasks sequentially and returns the results as an `AsyncResult`. * * @param tasks - An array of functions that return `MaybeAsyncResult` when executed. * @returns An `AsyncResult` containing the results of the executed tasks. */ export declare const sequenceAsync: MaybeAsyncResult)[]>(tasks: T) => AsyncResult<{ -readonly [K in keyof T]: OkTypeOf>>; }, ErrTypeOf>>;