[**@bondsports/general**](../README.md) • **Docs**

***

[@bondsports/general](../globals.md) / lazyChunk

# Function: lazyChunk()

> **lazyChunk**\<`T`\>(`arr`, `size`): `Generator`\<`T`[], `void`, `unknown`\>

Lazily yields consecutive slices ("chunks") of an array.

This is useful for batching work (DB inserts, API calls) without allocating
an array of all chunks up front.

## Type Parameters

• **T**

## Parameters

• **arr**: readonly `T`[]

Source array to chunk.

• **size**: `number`

Chunk size (must be a positive integer).

## Returns

`Generator`\<`T`[], `void`, `unknown`\>

A generator that yields chunks of `arr`.

## Example

```ts
for (const batch of lazyChunk(rows, 3)) {
  await repo.insert(batch);
}
```

## Defined in

[utils/array.util.ts:384](https://github.com/Bond-Sports/bondUtils/blob/545f16ceb055481acfd7641d7809c0f252d3a5e6/packages/general/src/utils/array.util.ts#L384)
