/** * Python itertools module for TypeScript * * Provides iterator building blocks inspired by Python's itertools module. * Includes functions for permutations, combinations, grouping, and chaining iterables. * * @see {@link https://docs.python.org/3/library/itertools.html | Python itertools documentation} * @module */ /** * Chain multiple iterables together into a single array * chain([1, 2], [3, 4]) -> [1, 2, 3, 4] */ declare function chain(...iterables: Iterable[]): T[]; /** * Return successive r-length combinations of elements * combinations([1, 2, 3], 2) -> [[1, 2], [1, 3], [2, 3]] */ declare function combinations(iterable: Iterable, r: number): T[][]; /** * Return successive r-length permutations of elements * permutations([1, 2, 3], 2) -> [[1, 2], [1, 3], [2, 1], [2, 3], [3, 1], [3, 2]] */ declare function permutations(iterable: Iterable, r?: number): T[][]; /** * Cartesian product of input iterables * product([1, 2], ['a', 'b']) -> [[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']] */ declare function product(...iterables: Iterable[]): T[][]; /** * Cycle through an iterable indefinitely (INFINITE - returns Generator) * cycle([1, 2, 3]) -> 1, 2, 3, 1, 2, 3, 1, 2, 3, ... * * WARNING: This is infinite! Use with for...of and break, or islice. */ declare function cycle(iterable: Iterable): Generator; /** * Repeat an object. If times is specified, returns an array. Otherwise returns * an infinite generator. * * repeat('x', 3) -> ['x', 'x', 'x'] * repeat('x') -> Generator that yields 'x' forever (INFINITE) */ declare function repeat(obj: T, times?: number): T[] | Generator; /** * Slice an iterable from start to stop with step * islice([1, 2, 3, 4, 5], 1, 4) -> [2, 3, 4] * islice([1, 2, 3, 4, 5], 3) -> [1, 2, 3] */ declare function islice(iterable: Iterable, start: number, stop?: number, step?: number): T[]; /** * Take elements while predicate is true * takeWhile(x => x < 5, [1, 4, 6, 4, 1]) -> [1, 4] */ declare function takeWhile(predicate: (x: T) => boolean, iterable: Iterable): T[]; /** * Skip elements while predicate is true, then return the rest * dropWhile(x => x < 5, [1, 4, 6, 4, 1]) -> [6, 4, 1] */ declare function dropWhile(predicate: (x: T) => boolean, iterable: Iterable): T[]; /** * Zip iterables together, filling missing values with fillvalue * zipLongest([1, 2, 3], ['a', 'b'], { fillvalue: '-' }) -> [[1, 'a'], [2, 'b'], [3, '-']] */ declare function zipLongest(...args: [...Iterable[], { fillvalue?: T; }] | Iterable[]): T[][]; /** * Return elements from iterable where the corresponding selector is true * compress([1, 2, 3, 4, 5], [1, 0, 1, 0, 1]) -> [1, 3, 5] */ declare function compress(data: Iterable, selectors: Iterable): T[]; /** * Return elements for which predicate is false * filterFalse(x => x % 2, [1, 2, 3, 4, 5]) -> [2, 4] */ declare function filterFalse(predicate: (x: T) => unknown, iterable: Iterable): T[]; /** * Make an iterator that returns accumulated sums or accumulated results * accumulate([1, 2, 3, 4, 5]) -> [1, 3, 6, 10, 15] * accumulate([1, 2, 3, 4, 5], (x, y) => x * y) -> [1, 2, 6, 24, 120] */ declare function accumulate(iterable: Iterable, func?: (acc: T, val: T) => T, initial?: T): T[]; /** * Return consecutive keys and groups from the iterable * groupby([1, 1, 2, 2, 2, 3, 1, 1]) -> [[1, [1, 1]], [2, [2, 2, 2]], [3, [3]], [1, [1, 1]]] */ declare function groupby(iterable: Iterable, key?: (x: T) => K): [K, T[]][]; /** * Make an iterator that returns evenly spaced values starting with n * count(10, 2) -> 10, 12, 14, 16, 18, ... (INFINITE Generator) */ declare function count(start?: number, step?: number): Generator; /** * Return n independent iterators from a single iterable * tee([1, 2, 3], 2) -> [[1, 2, 3], [1, 2, 3]] */ declare function tee(iterable: Iterable, n?: number): T[][]; /** * Return successive overlapping pairs from the iterable * pairwise([1, 2, 3, 4, 5]) -> [[1, 2], [2, 3], [3, 4], [4, 5]] */ declare function pairwise(iterable: Iterable): [T, T][]; /** * Cartesian product with repeat (product(range(3), repeat=2) like nested loops) * productRepeat([0, 1], 2) -> [[0, 0], [0, 1], [1, 0], [1, 1]] */ declare function productRepeat(iterable: Iterable, repeat?: number): T[][]; /** * Return r-length combinations with replacement * combinationsWithReplacement([1, 2, 3], 2) -> [[1, 1], [1, 2], [1, 3], [2, 2], [2, 3], [3, 3]] */ declare function combinationsWithReplacement(iterable: Iterable, r: number): T[][]; /** * Split an iterable into chunks of specified size. * @inspired Remeda, Lodash * * chunk([1, 2, 3, 4, 5], 2) -> [[1, 2], [3, 4], [5]] */ declare function chunk(iterable: Iterable, size: number): T[][]; /** * Partition an iterable into two arrays based on a predicate. * @inspired Remeda, Lodash * * partition([1, 2, 3, 4], x => x % 2 === 0) -> [[2, 4], [1, 3]] */ declare function partition(iterable: Iterable, predicate: (x: T) => boolean): [T[], T[]]; declare const itertoolsModule_accumulate: typeof accumulate; declare const itertoolsModule_chain: typeof chain; declare const itertoolsModule_chunk: typeof chunk; declare const itertoolsModule_combinations: typeof combinations; declare const itertoolsModule_combinationsWithReplacement: typeof combinationsWithReplacement; declare const itertoolsModule_compress: typeof compress; declare const itertoolsModule_count: typeof count; declare const itertoolsModule_cycle: typeof cycle; declare const itertoolsModule_dropWhile: typeof dropWhile; declare const itertoolsModule_filterFalse: typeof filterFalse; declare const itertoolsModule_groupby: typeof groupby; declare const itertoolsModule_islice: typeof islice; declare const itertoolsModule_pairwise: typeof pairwise; declare const itertoolsModule_partition: typeof partition; declare const itertoolsModule_permutations: typeof permutations; declare const itertoolsModule_product: typeof product; declare const itertoolsModule_productRepeat: typeof productRepeat; declare const itertoolsModule_repeat: typeof repeat; declare const itertoolsModule_takeWhile: typeof takeWhile; declare const itertoolsModule_tee: typeof tee; declare const itertoolsModule_zipLongest: typeof zipLongest; declare namespace itertoolsModule { export { itertoolsModule_accumulate as accumulate, itertoolsModule_chain as chain, itertoolsModule_chunk as chunk, itertoolsModule_combinations as combinations, itertoolsModule_combinationsWithReplacement as combinationsWithReplacement, itertoolsModule_compress as compress, itertoolsModule_count as count, itertoolsModule_cycle as cycle, itertoolsModule_dropWhile as dropWhile, itertoolsModule_filterFalse as filterFalse, itertoolsModule_groupby as groupby, itertoolsModule_islice as islice, itertoolsModule_pairwise as pairwise, itertoolsModule_partition as partition, itertoolsModule_permutations as permutations, itertoolsModule_product as product, itertoolsModule_productRepeat as productRepeat, itertoolsModule_repeat as repeat, itertoolsModule_takeWhile as takeWhile, itertoolsModule_tee as tee, itertoolsModule_zipLongest as zipLongest }; } export { accumulate as a, chunk as b, chain as c, combinations as d, combinationsWithReplacement as e, compress as f, count as g, cycle as h, itertoolsModule as i, dropWhile as j, filterFalse as k, groupby as l, islice as m, partition as n, permutations as o, pairwise as p, product as q, productRepeat as r, repeat as s, takeWhile as t, tee as u, zipLongest as z };