es-toolkit
Version:
A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.
22 lines • 958 B
TypeScript
//#region src/fp/array/forEach.d.ts
/**
* Creates a function that runs a callback for every element and returns the original array.
*
* This mirrors Remeda's pipeline-friendly `forEach` behavior: the side effect
* runs, then the input continues through the pipeline by reference. The returned
* function is lazy-capable inside {@link pipe}; when followed by a
* short-circuiting operator, the callback only runs for consumed values.
*
* @template T - The type of elements in the array.
* @param callback - Called with each value and index.
* @returns A function that performs the side effect and returns the original array.
*
* @example
* import { forEach, map, pipe } from 'es-toolkit/fp';
*
* pipe([1, 2, 3], forEach(value => console.log(value)), map(value => value * 2));
* // => [2, 4, 6]
*/
declare function forEach<T>(callback: (value: T, index: number) => void): (array: readonly T[]) => readonly T[];
//#endregion
export { forEach };