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/combinations.md.

combinations (Functional Programming) es-toolkit

Creates a function that returns combinations of a given size. Use it with pipe.

const result = pipe(array, combinations(size));
Info

Prefer the original es-toolkit combinations in ordinary code. Use this fp variant when composing transformations with pipe.

Usage

combinations returns every way to choose size values from the piped array while preserving their original order in each combination.

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

pipe(['a', 'b', 'c'], combinations(2)); // => [['a', 'b'], ['a', 'c'], ['b', 'c']]

Parameters

sizenumberrequired

The number of values in each combination.

Returns

A function that maps a readonly T[] to an array of combinations.

(array: readonly T[]) => T[][]

Throws

Throws an error if size is not a non-negative integer.

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.