Prelude API
    Preparing search index...

    Function window

    • Creates a generator that yields sliding windows of values from the source iterable.

      Type Parameters

      • T

        The type of elements in the source iterable.

      Parameters

      • n: number

        The window size (number of elements in each window).

      • yieldShorter: boolean = false

        Whether to yield a final window smaller than n if the source iterable ends (default: false).

      Returns (values: Iterable<T>) => Generator<T[]>

      A generator function that takes an iterable and yields arrays representing sliding windows.

      Arrays of length n containing consecutive elements from the source iterable.

      G.pipe(
      [1, 2, 3, 4, 5],
      G.window(3),
      G.array
      ) // [[1, 2, 3], [2, 3, 4], [3, 4, 5]]

      G.pipe(
      [1, 2],
      G.window(3, true),
      G.array
      ) // [[1, 2]]