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

xorBy (Functional Programming) es-toolkit

Creates a function that returns the symmetric difference by a mapped key. Use it with pipe.

const result = pipe(array, xorBy(secondArray, mapper));
Info

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

Usage

xorBy compares the values returned by mapper and returns values whose mapped key appears in exactly one array.

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

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

Parameters

secondArrayreadonly T[]required

The array to compare with the piped array.

mapper(item: T) => Urequired

The function that returns the comparison key.

Returns

A function that maps a readonly T[] to the symmetric difference 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.