docs/fp/reference/flatMap.md
Creates a function that maps each value to an array and flattens the result by one level. Use it with pipe.
const result = pipe(array, flatMap(callback));
::: info
Prefer the original es-toolkit flatMap in ordinary code. Use this fp variant when composing transformations with pipe.
:::
flatMap calls callback for each value in the piped array and concatenates the returned arrays. It is lazy-capable inside pipe.
import { flatMap, pipe } from 'es-toolkit/fp';
pipe(
[1, 2, 3],
flatMap(value => [value, value * 10])
); // => [1, 10, 2, 20, 3, 30]
callback ((value: T, index: number) => U[]): The function that maps each value to an array.((array: readonly T[]) => U[]): A function that maps a readonly T[] to a flattened array of callback results.