UNPKG

itertools-ts

Version:

Extended itertools port for TypeScript and JavaScript. Provides a huge set of functions for working with iterable collections (including async ones)

112 lines (111 loc) 4.68 kB
import { ZipTuple } from "./types"; /** * Iterate multiple iterable collections simultaneously. * * Make an iterator that aggregates items from multiple iterators. * Similar to Python's zip function. * * For uneven lengths, iterations stops when the shortest iterable is exhausted. * * @param iterables */ export declare function zip<T extends Array<Iterable<unknown> | Iterator<unknown>>>(...iterables: T): Iterable<ZipTuple<T, never>>; /** * Iterate multiple async iterable collections simultaneously. * * Make an iterator that aggregates items from multiple iterators. * Similar to Python's zip function. * * For uneven lengths, iterations stops when the shortest iterable is exhausted. * * @param iterables */ export declare function zipAsync<T extends Array<AsyncIterable<unknown> | AsyncIterator<unknown> | Iterable<unknown> | Iterator<unknown>>>(...iterables: T): AsyncIterable<ZipTuple<T, never>>; /** * Iterate multiple iterable collections simultaneously. * * Make an iterable that aggregates items from multiple iterators. * Similar to Python's zip_longest function. * * Iteration continues until the longest iterable is exhausted. * For uneven lengths, the exhausted iterables will produce `filler` value for the remaining iterations. * * @param filler * @param iterables */ export declare function zipFilled<T extends Array<Iterable<unknown> | Iterator<unknown>>, F>(filler: F, ...iterables: T): Iterable<ZipTuple<T, F>>; /** * Iterate multiple async iterable collections simultaneously. * * Make an iterable that aggregates items from multiple iterators. * Similar to Python's zip_longest function. * * Iteration continues until the longest iterable is exhausted. * For uneven lengths, the exhausted iterables will produce `filler` value for the remaining iterations. * * @param filler * @param iterables */ export declare function zipFilledAsync<T extends Array<AsyncIterable<unknown> | AsyncIterator<unknown> | Iterable<unknown> | Iterator<unknown>>, F>(filler: F, ...iterables: T): AsyncIterable<ZipTuple<T, F>>; /** * Iterate multiple iterable collections simultaneously. * * Make an iterable that aggregates items from multiple iterators. * Similar to Python's zip_longest function. * * Iteration continues until the longest iterable is exhausted. * For uneven lengths, the exhausted iterables will produce `undefined` for the remaining iterations. * * @param iterables */ export declare function zipLongest<T extends Array<Iterable<unknown> | Iterator<unknown>>>(...iterables: T): Iterable<ZipTuple<T, undefined>>; /** * Iterate multiple async iterable collections simultaneously. * * Make an iterable that aggregates items from multiple iterators. * Similar to Python's zip_longest function. * * Iteration continues until the longest iterable is exhausted. * For uneven lengths, the exhausted iterables will produce `undefined` for the remaining iterations. * * @param iterables */ export declare function zipLongestAsync<T extends Array<AsyncIterable<unknown> | AsyncIterator<unknown> | Iterable<unknown> | Iterator<unknown>>>(...iterables: T): AsyncIterable<ZipTuple<T, undefined>>; /** * Iterate multiple iterable collections of equal lengths simultaneously. * * Works like multi.zip() method but throws LengthException if lengths not equal, * i.e., at least one iterator ends before the others. * * @param iterables * * @throws LengthError if iterators lengths not equal. */ export declare function zipEqual<T extends Array<Iterable<unknown> | Iterator<unknown>>>(...iterables: T): Iterable<ZipTuple<T, never>>; /** * Iterate multiple async iterable collections of equal lengths simultaneously. * * Works like multi.zipAsync() method but throws LengthException if lengths not equal, * i.e., at least one iterator ends before the others. * * @param iterables * * @throws LengthError if iterators lengths not equal. */ export declare function zipEqualAsync<T extends Array<AsyncIterable<unknown> | AsyncIterator<unknown> | Iterable<unknown> | Iterator<unknown>>>(...iterables: T): AsyncIterable<ZipTuple<T, never>>; /** * Chain multiple iterables together into a single iteration. * * Makes a single continuous sequence out of multiple sequences. * * @param iterables */ export declare function chain<T>(...iterables: Array<Iterable<T> | Iterator<T>>): Iterable<T>; /** * Chain multiple async iterables together into a single iteration. * * Makes a single continuous sequence out of multiple sequences. * * @param iterables */ export declare function chainAsync<T>(...iterables: Array<AsyncIterable<T> | AsyncIterator<T> | Iterable<T> | Iterator<T>>): AsyncIterable<T>;