For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /reference/fp/map.md.

map (Functional Programming) es-toolkit

Creates a function that transforms every element of an array, equivalent to Array.prototype.map. Use it with pipe.

const result = pipe(array, map(callbackfn));
Info

This helper is specific to es-toolkit/fp. Use it when you want this operation as part of a pipe pipeline.

Usage

map builds a new array by calling callbackfn on each element. It is lazy-capable: inside a pipe it is fused with adjacent lazy operations, so a trailing take can stop the work early.

import { map, pipe } from 'es-toolkit/fp';

// Transform each element.
pipe(
  [1, 2, 3],
  map(x => x * 2)
); // => [2, 4, 6]

// The index is available as the second argument.
pipe(
  [10, 20, 30],
  map((value, index) => value + index)
); // => [10, 21, 32]

// The element type can change.
pipe(
  [1, 2, 3],
  map(x => `#${x}`)
); // => ['#1', '#2', '#3']

Parameters

callbackfn(value: T, index: number) => Urequired

A function called for each element; its return value becomes the corresponding element of the output array.

Returns

A function that maps a readonly T[] to a new U[].

(array: readonly T[]) => U[]
Source: es-toolkit

Re-exported verbatim from es-toolkit. Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.