import { TypeGuard } from './guards.js'; /** * A wrapper around Iterable that provides chainable transformation methods. * Each method returns a new ExtendedIterable wrapping the source, * mirroring how Array methods work but with lazy evaluation. * * @example * ```typescript * const numbers = new ExtendedIterable([1, 2, 3]); * const doubled = numbers.map(x => x * 2).collect(); // [2, 4, 6] * * // Works with any iterable, including generators * const result = new ExtendedIterable(myGenerator()) * .map(transform) * .join(', '); * ``` */ export declare class ExtendedIterable implements Iterable { private _iterFn; constructor(iterable: Iterable); private static _from; /** * Flattens one level of nesting by yielding elements from nested iterables. * Non-iterable values are yielded as-is. Strings are not split into characters. */ flat(): ExtendedIterable ? U : T>; /** * Maps each element through a transformation function. * Evaluation is lazy - the function is called only when iterating. */ map(fn: (val: T) => T2): ExtendedIterable; filter(predicate: (val: T) => boolean): ExtendedIterable; filter(predicate: (val: T) => TypeGuard): ExtendedIterable; /** * Takes the first n elements. */ take(n: number): ExtendedIterable; /** * Tests whether at least one element passes the predicate. * Short-circuits on first match. * Supports both sync and async predicates - returns Promise if predicate is async. */ some(predicate: (val: T) => boolean): boolean; some(predicate: (val: T) => Promise): Promise; /** * Returns the first element that passes the predicate, or undefined. * Short-circuits on first match. * Supports both sync and async predicates - returns Promise if predicate is async. */ find(predicate: (val: T) => boolean): T | undefined; find(predicate: (val: T) => Promise): Promise; /** * Reduces the iterable to a single value by applying a function against * an accumulator and each element. * * Without an initial value, the first element is used as the accumulator * and reduction starts from the second element. Throws TypeError on empty iterables. * * @example * ```typescript * iter([1, 2, 3]).reduce((sum, n) => sum + n); // 6 * iter([1, 2, 3]).reduce((sum, n) => sum + n, 10); // 16 * ``` */ reduce(fn: (acc: T, val: T) => T): T; reduce(fn: (acc: U, val: T) => U, initialValue: U): U; /** * Collects all elements into an array. */ collect(): T[]; /** * Joins all elements into a string with a separator. * Elements are converted to strings using toString(). */ join(separator: string): string; /** * Prepends an iterable to the start of this iterable. */ prefix(prefix: Iterable): ExtendedIterable; /** * Removes elements from the iterable and optionally inserts new elements. * Returns both the modified iterable and the deleted elements. * Both iterables share state - iterating either will cache results for the other. * * @param matcher - Predicate to find the splice position * @param deleteCount - Number of elements to remove after the match * @param insertIterable - Elements to insert after removing * @returns Object with `sliced` (modified iterable) and `deleted` (removed elements) * * @example * ```typescript * const { deleted, sliced } = iter([1, 2, 3, 4, 5]) * .splice((el) => el === 3, 2, iter([10, 20])); * sliced.collect(); // [1, 2, 10, 20, 5] * deleted.collect(); // [3, 4] * ``` */ splice(matcher: (val: T) => boolean, deleteCount: number, insertIterable: Iterable): { deleted: ExtendedIterable; sliced: ExtendedIterable; }; [Symbol.iterator](): Iterator; } export declare class AsyncExtendedIterable implements AsyncIterable { private asyncIterable; constructor(iterable: AsyncIterable | Iterable); /** * Maps each element through a transformation function. * The function can be sync or async. * Evaluation is lazy - the function is called only when iterating. */ map(fn: (val: T) => T2 | Promise): AsyncExtendedIterable; filter(predicate: (val: T) => boolean | Promise): AsyncExtendedIterable; filter(predicate: (val: T) => TypeGuard): AsyncExtendedIterable; /** * Reduces the async iterable to a single value. * Without an initial value, the first element is used as the accumulator. * Throws TypeError on empty iterables when no initial value is provided. */ reduce(fn: (acc: T, val: T) => T | Promise): Promise; reduce(fn: (acc: U, val: T) => U | Promise, initialValue: U): Promise; /** * Collects all elements into an array. */ collect(): Promise; /** * Joins all elements into a string with a separator. * Elements are converted to strings using String(). */ join(separator: string): Promise; /** * Takes the first n elements. */ take(n: number): AsyncExtendedIterable; /** * Tests whether at least one element passes the predicate. * Short-circuits on first match. Predicate can be sync or async. */ some(predicate: (val: T) => boolean | Promise): Promise; /** * Returns the first element that passes the predicate, or undefined. * Short-circuits on first match. Predicate can be sync or async. */ find(predicate: (val: T) => boolean | Promise): Promise; /** * Removes elements from the async iterable and optionally inserts new elements. * Returns both the modified iterable and the deleted elements. * Both iterables share state - iterating either will cache results for the other. */ splice(matcher: (val: T) => boolean | Promise, deleteCount: number, insertIterable: AsyncIterable | Iterable): Promise<{ deleted: AsyncExtendedIterable; sliced: AsyncExtendedIterable; }>; [Symbol.asyncIterator](): AsyncIterator; } /** * Helper to create an AsyncExtendedIterable from any iterable. */ export declare function asyncIter(iterable: AsyncIterable | Iterable): AsyncExtendedIterable; /** * Returns an AsyncExtendedIterable that yields promise results as they settle, * in completion order (not input order). * * Like Promise.allSettled, but streaming - you get results as soon as they're ready, * with full chaining support. * * @example * ```typescript * const promises = [ * fetch('/slow'), // takes 3s * fetch('/fast'), // takes 1s * fetch('/medium'), // takes 2s * ]; * * // Results arrive in order: fast, medium, slow * for await (const result of asSettled(promises)) { * if (result.status === 'fulfilled') { * console.log('Got:', result.value); * } else { * console.log('Failed:', result.reason); * } * } * * // Chain operations * const firstThreeSuccesses = await asSettled(promises) * .filter(r => r.status === 'fulfilled') * .map(r => (r as PromiseFulfilledResult).value) * .take(3) * .collect(); * ``` */ export declare function asSettled(promises: Iterable>): AsyncExtendedIterable>; /** * Helper to create an ExtendedIterable from any iterable. */ export declare function iter(iterable: Iterable): ExtendedIterable; //# sourceMappingURL=extended-iterable.d.ts.map