@jiminp/tooltool
    Preparing search index...

    Function batchedMap

    • Asynchronously maps an array in batches and concatenates the results.

      • If batch_size > 0, the array is split into consecutive batches of up to batch_size elements and processed sequentially.
      • If batch_size === 0, the entire array is passed as a single batch (with index = 0).

      The mapping function fn may return:

      • an array of output items, which are appended to the final result, or
      • null / undefined, which is simply treated as an empty array ([]).

      Type Parameters

      • T

        Type of input items.

      • U

        Type of mapped output items.

      Parameters

      • arr: T[]

        The array to map.

      • batch_size: number

        Items per batch. 0 means “use the entire array as one batch”. Must be a non-negative safe integer.

      • fn: (batch: T[], index: number) => Promise<Nullable<U[]>>

        Async mapper invoked for each batch.

        • batch: A slice of arr (or the entire array when batch_size === 0).
        • index: The starting index of batch within arr.

      Returns Promise<U[]>

      A promise resolving to a flat array containing all mapped items.

      If batch_size is negative or not a safe integer.

      // Normal batch mapping
      const out = await batchedMap([1,2,3], 2, async(batch) => batch.map(x => x * 2));
      // -> [2,4,6]