@mirei/ts-collections
    Preparing search index...

    Function windows

    • Produces a sequence of sliding windows of fixed size over source.

      Type Parameters

      • TElement

        Type of elements within source.

      Parameters

      • source: Iterable<TElement>

        The iterable to window.

      • size: number

        Length of each window; must be at least 1.

      Returns IEnumerable<IEnumerable<TElement>>

      A deferred sequence where each element exposes one contiguous window from source.

      Thrown when size is less than 1.

      Re-throws any error thrown while iterating source.

      Windows overlap and are yielded only after enough source elements are observed to fill size. Trailing partial windows are omitted.

      const numbers = [1, 2, 3, 4, 5];
      const windows = windows(numbers, 3);
      console.log(windows.select(w => w.toArray()).toArray()); // [[1, 2, 3], [2, 3, 4], [3, 4, 5]]