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

cartesianProduct (Functional Programming) es-toolkit

Creates a function that computes the Cartesian product with the piped array. Use it with pipe.

const result = pipe(array, cartesianProduct(...arrs));
Info

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

Usage

cartesianProduct returns every possible tuple formed by taking one value from the piped array and one value from each configured array. The rightmost array advances fastest.

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

pipe([1, 2], cartesianProduct(['a', 'b'])); // => [[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']]

pipe([], cartesianProduct(['a', 'b'])); // => []

Parameters

arrsArray<readonly T[]>required

The arrays to include after the piped array.

Returns

A function that maps the piped array to the Cartesian-product tuples.

(array: readonly T[]) => T[][]
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.