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

uniqBy (Functional Programming) es-toolkit

Creates a function that removes duplicates by a mapped key. Use it with pipe.

const result = pipe(array, uniqBy(mapper));
Info

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

Usage

uniqBy keeps the first value for each key returned by mapper. It preserves the order of first occurrence and is lazy-capable inside pipe.

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

pipe(
  [{ id: 1 }, { id: 1 }, { id: 2 }],
  uniqBy(item => item.id)
); // => [{ id: 1 }, { id: 2 }]

Parameters

mapper(item: T, index: number) => Urequired

The function that returns the key used for uniqueness.

Returns

A function that maps a readonly T[] to a duplicate-free array by key.

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