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

intersectionWith (Functional Programming) es-toolkit

Creates a function that keeps values using a custom equality function. Use it with pipe.

const result = pipe(array, intersectionWith(secondArray, areItemsEqual));
Info

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

Usage

intersectionWith keeps values from the piped array when areItemsEqual returns true for at least one value in secondArray.

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

pipe(
  [{ id: 1 }, { id: 2 }],
  intersectionWith([{ id: 2 }], (a, b) => a.id === b.id)
); // => [{ id: 2 }]

Parameters

secondArrayreadonly U[]required

The array containing values to compare against.

areItemsEqual(item: T, other: U) => booleanrequired

The function that decides whether two values are equal.

Returns

A function that maps a readonly T[] to values matched by the comparator.

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