> For AI agents: the complete documentation index is available at https://massaman.dev/llms.txt, the full documentation bundle is available at https://massaman.dev/llms-full.txt.

# chunkBy (Functional Programming) es-toolkit

Creates a function that splits adjacent values whenever a key changes. Use it with [`pipe`](https://massaman.dev/reference/fp/pipe.md).

```typescript
const result = pipe(array, chunkBy(iteratee));
```

::: info

This helper is specific to `es-toolkit/fp`. Use it when you want this operation as part of a [`pipe`](https://massaman.dev/reference/fp/pipe.md) pipeline.

:::

## Usage

`chunkBy` walks the piped array from left to right and groups adjacent values while `iteratee` returns the same key. A new chunk starts when the key changes.

```typescript
import { chunkBy, pipe } from 'es-toolkit/fp';

pipe(
  [1, 1, 2, 2, 1],
  chunkBy(value => value)
); // => [[1, 1], [2, 2], [1]]
```

#### Parameters


iteratee(value: T) => unknownrequired

The function that returns the grouping key for each value.

#### Returns

A function that maps a `readonly T[]` to chunks of adjacent values.

```typescript
(array: readonly T[]) => T[][]
```


Source: es-toolkit

Re-exported verbatim from [`es-toolkit`](https://es-toolkit.dev/fp/reference/chunkBy.html). Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.
