Function windows

  • Yields sliding windows (tuples) of length from the input iterator. Each window is separated by offset number of elements.

    Type Parameters

    • T
    • Length extends number

    Parameters

    • length: Length

      The length of each window, must be greater than 0.

    • offset: number

      The offset of each window from each other. Must be greater than 0.

    • fill: T

      Optional, the value to fill the last window with if it's not the same length as the rest of the iterator.

    Returns ((arg: IteratorOrIterable<T>) => IterableIterator<Tuple<T, Length>>)

    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]]
  • Type Parameters

    • T
    • Length extends number

    Parameters

    Returns ((arg: T) => IterableIterator<IterSource<T>[]>)

  • Type Parameters

    • T
    • Length extends number

    Parameters

    Returns IterableIterator<Tuple<T, Length>>

  • Type Parameters

    • T
    • Length extends number

    Parameters

    Returns IterableIterator<T[]>