UNPKG

iteragain

Version:

Javascript Iterable/Iterator/Generator-function utilities.

19 lines 1.39 kB
import type { IterSource, IteratorOrIterable, Tuple } from './types'; /** * Yields sliding windows (tuples) of `length` from the input iterator. Each window is separated by `offset` number of * elements. * @param arg The input iterator. * @param length The length of each window, must be greater than 0. * @param offset The offset of each window from each other. Must be greater than 0. * @param fill Optional, the value to fill the last window with if it's not the same length as the rest of the iterator. * @example * toArray(windows([1,2,3,4,5], 2, 1)) // [[1,2], [2,3], [3,4], [4,5]] * toArray(windows([1,2,3,4,5], 2, 3)) // [[1,2], [4,5]] * toArray(windows([1,2,3,4,5], 3, 3, 0)) // [[1,2,3], [4,5,0]] */ export declare function windows<T, Length extends number>(length: Length, offset: number, fill: T): (arg: IteratorOrIterable<T>) => IterableIterator<Tuple<T, Length>>; export declare function windows<T, Length extends number>(length: Length, offset: number): (arg: T) => IterableIterator<IterSource<T>[]>; export declare function windows<T, Length extends number>(arg: IteratorOrIterable<T>, length: Length, offset: number, fill: T): IterableIterator<Tuple<T, Length>>; export declare function windows<T, Length extends number>(arg: IteratorOrIterable<T>, length: Length, offset: number): IterableIterator<T[]>; export default windows; //# sourceMappingURL=windows.d.ts.map