> 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.

# flatMap (Functional Programming) es-toolkit

Creates a function that maps each value to an array and flattens the result by one level. Use it with [`pipe`](https://massaman.dev/reference/fp/pipe.md).

```typescript
const result = pipe(array, flatMap(callback));
```

::: info

Prefer the original es-toolkit [`flatMap`](https://massaman.dev/reference/array/flatMap.md) in ordinary code. Use this `fp` variant when composing transformations with [`pipe`](https://massaman.dev/reference/fp/pipe.md).

:::

## Usage

`flatMap` calls `callback` for each value in the piped array and concatenates the returned arrays. It is lazy-capable inside [`pipe`](https://massaman.dev/reference/fp/pipe.md).

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

pipe(
  [1, 2, 3],
  flatMap(value => [value, value * 10])
); // => [1, 10, 2, 20, 3, 30]
```

#### Parameters


callback(value: T, index: number) => U[]required

The function that maps each value to an array.

#### Returns

A function that maps a `readonly T[]` to a flattened array of callback results.

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


Source: es-toolkit

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