interface OkResult { readonly value: T; readonly isOk: true; readonly isErr: false; readonly isError: false; map(fn: (data: T) => S): OkResult; mapErr(fn: (error: never) => unknown): OkResult; chain(next: (data: T) => Result$1): Result$1; chainErr(next: (error: never) => Result$1): OkResult; unwrap(): T; unwrapOr(fallback: unknown): T; unwrapOrElse(fallback: (error: never) => unknown): T; unwrapErr(): never; unwrapErrOr(fallback: F): F; unwrapErrOrElse(fallback: (value: T) => F): F; unwrapOrThrow(): T; unpack(): T; match(okMatcher: (data: T) => TR, errMatcher: (error: never) => ER): TR; tap(fn: (data: T) => void): OkResult; tapErr(fn: unknown): OkResult; biMap(okFn: (data: T) => S, errFn: (error: never) => F): OkResult; biChain(okFn: (data: T) => Result$1, errFn: (error: never) => Result$1): Result$1; asTuple(): [ok: true, error: undefined, value: T]; [Symbol.iterator](): Generator; } interface ErrResult { readonly error: E; readonly isOk: false; readonly isErr: true; readonly isError: true; map(fn: (data: never) => unknown): ErrResult; mapErr(fn: (error: E) => F): ErrResult; chain(next: (value: never) => Result$1): ErrResult; chainErr(next: (error: E) => Result$1): Result$1; unwrap(): never; unwrapOr(fallback: S): S; unwrapOrElse(fallback: (error: E) => S): S; unwrapErr(): E; unwrapErrOr(fallback: F): E; unwrapErrOrElse(fallback: (value: never) => unknown): E; unwrapOrThrow(): never; unpack(): E; match(okMatcher: (value: never) => TR, errMatcher: (error: E) => ER): ER; tap(fn: (value: never) => unknown): ErrResult; tapErr(fn: (error: E) => void): ErrResult; biMap(okFn: (value: never) => S, errFn: (error: E) => F): ErrResult; biChain(okFn: (value: never) => Result$1, errFn: (error: E) => Result$1): Result$1; asTuple(): [ok: false, error: E, value: undefined]; [Symbol.iterator](): Generator; } type Result$1 = OkResult | ErrResult; type NotResultOf = T extends Result$1 ? never : T; type ErrTypeOf = T extends ErrResult ? E : never; type OkTypeOf = T extends OkResult ? R : never; type AsyncResult = Promise>; type AsyncOk = AsyncResult; type AsyncErr = AsyncResult; type MaybeAsync = T | Promise; type MaybeAsyncResult = Result$1 | AsyncResult; type Collected = { -readonly [K in keyof R]: OkTypeOf; }; type CollectedErr = { -readonly [K in keyof R]: ErrTypeOf; }; type AsyncCollected = { -readonly [K in keyof T]: OkTypeOf>; }; type ResultOf Result$1> = Result$1>, ErrTypeOf>>; type OkType = OkResult; declare const ok: (value: T) => OkType; declare const asyncOk: (value: T | Promise) => AsyncOk; type ErrType = ErrResult; declare const err: (error: E) => ErrType; declare const asyncErr: (error: E | Promise) => AsyncErr; declare function rTry(fn: (...args: Args) => never, ...args: Args): ErrResult; declare function rTry(fn: () => Promise, ...args: Args): Promise>; declare function rTry(fn: (...args: Args) => T, ...args: Args): Result$1; declare function rTry(promise: Promise): Promise>; declare function rTry(value: T): Result$1; declare const isResult: (value: unknown) => value is Result$1; declare const isOk: (value: Result$1) => value is OkResult; declare const isError: (value: Result$1) => value is ErrResult; declare const isErr: (value: Result$1) => value is ErrResult; declare const ensureResult: (value: T | Result$1) => Result$1; declare const okIf: { (value: T, guard: (data: T) => data is S, fallback: F | ((value: Exclude) => F)): Result$1; (value: T, predicate: (data: T) => boolean, fallback: F | ((value: T) => F)): Result$1; }; declare const expect: { (guard: (data: T) => data is S, fallback: F | ((value: Exclude) => F)): (value: T) => Result$1; (predicate: (data: T) => boolean, fallback: F | ((value: T) => F)): (value: T) => Result$1; }; declare const expectExists: (fallback: E | ((value: undefined | null) => E)) => (value: T | undefined | null) => Result$1; declare const okIfExists: (value: T | undefined | null, fallback: E | ((value: undefined | null) => E)) => Result$1; type Job = () => Generator; type Method = { (this: This): Generator; }; type AsyncJob = () => AsyncGenerator; type AsyncMethod = { (this: This): AsyncGenerator; }; declare function Do(job: AsyncJob): Promise | NotResultOf, E | ErrTypeOf>>; declare function Do(method: AsyncMethod, thisArg: This): Promise | NotResultOf, E | ErrTypeOf>>; declare function Do(job: Job): Result$1 | NotResultOf, E | ErrTypeOf>; declare function Do(method: Method, thisArg: This): Result$1 | NotResultOf, E | ErrTypeOf>; /** * 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. */ declare const reduce: (results: readonly Result$1[], reducer: (acc: S, result: T, index: number, list: readonly Result$1[]) => S, initial: S) => Result$1; /** * 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. */ declare const reduceErr: (results: readonly Result$1[], reducer: (acc: S, err: E) => S, initial: S) => Result$1; /** * 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. */ declare const collect: []>(results: R) => Result$1, 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. */ declare const collectErr: []>(results: R) => Result$1, 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. */ 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. */ 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. */ declare const separate: []>(results: R) => [Result$1, never>, Result$1>]; /** * 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. */ declare const collectAll: []>(results: R) => Result$1, [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. */ declare const sequence: Result$1)[]>(tasks: T) => Result$1<{ -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. */ declare const sequenceAsync: MaybeAsyncResult)[]>(tasks: T) => AsyncResult<{ -readonly [K in keyof T]: OkTypeOf>>; }, ErrTypeOf>>; declare const map: (fn: (data: T) => S) => (result: Result$1) => Result$1; declare const mapErr: (fn: (error: E) => F) => (result: Result$1) => Result$1; declare const chain: (next: (data: T) => Result$1) => (result: Result$1) => Result$1; declare const chainErr: (next: (error: E) => Result$1) => (result: Result$1) => Result$1; declare const unwrap: (result: Result$1) => T; declare const unwrapOr: (fallback: S) => (result: Result$1) => T | S; declare const unwrapOrThrow: (result: Result$1) => T; declare const unwrapOrElse: (fallback: (error: E) => S) => (result: Result$1) => T | S; declare const unwrapErr: (result: Result$1) => E; declare const unwrapErrOr: (fallback: F) => (result: Result$1) => E | F; declare const unwrapErrOrElse: (fallback: (data: T) => F) => (result: Result$1) => E | F; declare const unpack: (result: Result$1) => E | T; declare const match: (okMatcher: (data: T) => TR, errMatcher: (error: E) => ER) => (result: Result$1) => ER | TR; declare const tap: (fn: (data: T) => void) => (result: Result$1) => Result$1; declare const tapErr: (fn: (error: E) => void) => (result: Result$1) => Result$1; declare const biMap: (okFn: (data: T) => S, errFn: (error: E) => F) => (result: Result$1) => Result$1; declare const biChain: (okFn: (data: T) => Result$1, errFn: (error: E) => Result$1) => (result: Result$1) => Result$1; declare const asTuple: (result: Result$1) => [ok: true, error: undefined, value: T] | [ok: false, error: E, value: undefined]; declare const thenMap: (fn: (data: T) => S) => (asyncRes: AsyncResult) => AsyncResult; declare const thenMapErr: (fn: (error: E) => F) => (asyncRes: AsyncResult) => AsyncResult; declare const thenChain: (next: (data: T) => MaybeAsyncResult) => (asyncRes: AsyncResult) => AsyncResult; declare const thenChainErr: (next: (error: E) => MaybeAsyncResult) => (asyncRes: AsyncResult) => AsyncResult; declare const thenMatch: (okMatcher: (data: T) => TR, errMatcher: (error: E) => ER) => (asyncRes: AsyncResult) => Promise; declare const thenUnwrap: (asyncRes: AsyncResult) => Promise; declare const thenUnwrapOr: (fallback: S) => (asyncRes: AsyncResult) => Promise; declare const thenUnwrapOrElse: (fallback: (error: E) => S) => (asyncRes: AsyncResult) => Promise; declare const thenUnwrapOrReject: (asyncRes: AsyncResult) => Promise; declare const thenUnwrapErr: (asyncRes: AsyncResult) => Promise; declare const thenUnwrapErrOr: (fallback: F) => (asyncRes: AsyncResult) => Promise; declare const thenUnwrapErrOrElse: (fallback: (data: T) => F) => (asyncRes: AsyncResult) => Promise; declare const thenTap: (fn: (data: T) => void) => (asyncRes: AsyncResult) => AsyncResult; declare const thenTapAndWait: (fn: (data: T) => Promise) => (asyncRes: AsyncResult) => AsyncResult; declare const thenTapErr: (fn: (error: E) => void) => (asyncRes: AsyncResult) => AsyncResult; declare const thenTapErrAndWait: (fn: (error: E) => Promise) => (asyncRes: AsyncResult) => AsyncResult; declare const flip: (result: Result$1, E | Promise>) => AsyncResult; declare const from: (result: Result$1) => AsyncResult; declare const thenUnpack: (asyncRes: AsyncResult) => Promise; type ResolveAwaitedOks

= { [K in keyof P]: P[K] extends Awaited> ? T : P[K]; }; declare const error: (error: E) => ErrResult; declare const asyncError: (error: E | Promise) => AsyncErr; type Result = Result$1; declare const Result: { ok: (value: T) => OkResult; asyncOk: (value: T | Promise) => AsyncOk; err: (error: E) => ErrResult; error: (error: E) => ErrResult; asyncErr: (error: E | Promise) => AsyncErr; asyncError: (error: E | Promise) => AsyncErr; try: typeof rTry; }; export { type AsyncResult, Do, type ErrResult, type ErrTypeOf, type MaybeAsync, type MaybeAsyncResult, type OkResult, type OkTypeOf, type ResolveAwaitedOks, Result, type ResultOf, asTuple, asyncErr, asyncError, asyncOk, biChain, biMap, chain, chainErr, collect, collectAll, collectAsync, collectErr, ensureResult, err, error, expect, expectExists, flip, from, isErr, isError, isOk, isResult, map, mapErr, match, ok, okIf, okIfExists, partition, reduce, reduceErr, separate, sequence, sequenceAsync, tap, tapErr, thenChain, thenChainErr, thenMap, thenMapErr, thenMatch, thenTap, thenTapAndWait, thenTapErr, thenTapErrAndWait, thenUnpack, thenUnwrap, thenUnwrapErr, thenUnwrapErrOr, thenUnwrapErrOrElse, thenUnwrapOr, thenUnwrapOrElse, thenUnwrapOrReject, unpack, unwrap, unwrapErr, unwrapErrOr, unwrapErrOrElse, unwrapOr, unwrapOrElse, unwrapOrThrow };