Back to Es Toolkit

add (Functional Programming)

docs/fp/reference/add.md

1.49.0917 B
Original Source

add (Functional Programming)

Creates a function that adds a number to its input. Use it with pipe.

typescript
const result = pipe(value, add(addend));

::: info

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

:::

Usage

add returns a function that adds addend to its input. It is designed for composition: it can transform the value flowing through a pipe, or serve as the callback of a function such as map.

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

// Transform the piped value.
pipe(3, add(2)); // => 5

// Use as a map callback.
pipe([1, 2, 3], map(add(10))); // => [11, 12, 13]

Parameters

  • addend (number): The number to add to the input.

Returns

((value: number) => number): A function that maps value to value + addend.