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

union (Functional Programming) es-toolkit

Creates a function that combines two arrays without duplicate values. Use it with pipe.

const result = pipe(array, union(secondArray));
Info

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

Usage

union returns unique values from the piped array followed by values from secondArray that have not appeared yet.

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

pipe([1, 2, 2], union([2, 3])); // => [1, 2, 3]

Parameters

secondArrayreadonly T[]required

The array to combine after the piped array.

Returns

A function that maps a readonly T[] to the union of both arrays.

(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.