/** * MaybePromise utilities for transparent async support. * * The sync path stays zero-overhead — when no async JS functions are involved, * everything runs synchronously with only `instanceof Promise` checks as overhead. * When an async value is detected, the evaluation chain switches to Promise-based * execution for the remainder. */ export type MaybePromise = T | Promise; /** * Chain a value that might be a Promise. If the value is sync, calls fn synchronously. * If it's a Promise, chains with .then(). */ export declare function chain(value: MaybePromise, fn: (v: T) => MaybePromise): MaybePromise; /** * Like Array.map but handles MaybePromise callbacks sequentially. * In the sync case, runs as a simple loop. Switches to async only when needed. */ export declare function mapSequential(arr: readonly T[], fn: (elem: T, index: number) => MaybePromise): MaybePromise; /** * Like Array.reduce but handles MaybePromise callbacks sequentially. * In the sync case, runs as a simple loop. Switches to async only when needed. */ export declare function reduceSequential(arr: readonly T[], fn: (acc: U, elem: T, index: number) => MaybePromise, initial: U): MaybePromise; /** * Like Array.forEach but handles MaybePromise callbacks sequentially. * In the sync case, runs as a simple loop. Switches to async only when needed. */ export declare function forEachSequential(arr: readonly T[], fn: (elem: T, index: number) => MaybePromise): MaybePromise; /** * Try/catch that handles MaybePromise values correctly. * If tryFn returns a Promise, catches both sync throws and Promise rejections. */ export declare function tryCatch(tryFn: () => MaybePromise, catchFn: (error: unknown) => MaybePromise): MaybePromise; /** * Like Array.some but handles MaybePromise callbacks sequentially. * Returns the first truthy MaybePromise result, or false. */ export declare function someSequential(arr: readonly T[], fn: (elem: T, index: number) => MaybePromise): MaybePromise; /** * Like Array.every but handles MaybePromise callbacks sequentially. * Returns false as soon as a falsy result is found. */ export declare function everySequential(arr: readonly T[], fn: (elem: T, index: number) => MaybePromise): MaybePromise; /** * Like Array.filter but handles MaybePromise callbacks sequentially. * Returns the filtered array. */ export declare function filterSequential(arr: readonly T[], fn: (elem: T, index: number) => MaybePromise): MaybePromise; /** * Like Array.findIndex but handles MaybePromise callbacks sequentially. * Returns -1 if no element matches. */ export declare function findIndexSequential(arr: readonly T[], fn: (elem: T, index: number) => MaybePromise): MaybePromise;