Prelude API
    Preparing search index...

    Function batch

    • Creates a generator that groups values from an iterable into batches of a specified size.

      Parameters

      • n: number

        The size of each batch

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

      A function that takes an iterable and returns a generator

      Arrays of elements, with each array containing up to n elements The last batch may have fewer than n elements (between 1 and n)

      // Group an array into batches of 3
      const batchedValues = [...batch(3)([1, 2, 3, 4, 5, 6, 7])]
      // Result: [[1, 2, 3], [4, 5, 6], [7]]