> For AI agents: the complete documentation index is available at https://massaman.dev/llms.txt, the full documentation bundle is available at https://massaman.dev/llms-full.txt.

# differenceWith (Functional Programming) es-toolkit

Creates a function that excludes values using a custom equality function. Use it with [`pipe`](https://massaman.dev/reference/fp/pipe.md).

```typescript
const result = pipe(array, differenceWith(secondArray, areItemsEqual));
```

::: info

Prefer the original es-toolkit [`differenceWith`](https://massaman.dev/reference/array/differenceWith.md) in ordinary code. Use this `fp` variant when composing transformations with [`pipe`](https://massaman.dev/reference/fp/pipe.md).

:::

## Usage

`differenceWith` keeps values from the piped array only when `areItemsEqual` returns `false` for every value in `secondArray`.

```typescript
import { differenceWith, pipe } from 'es-toolkit/fp';

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

#### 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 not matched by the comparator.

```typescript
(array: readonly T[]) => T[]
```


Source: es-toolkit

Re-exported verbatim from [`es-toolkit`](https://es-toolkit.dev/fp/reference/differenceWith.html). Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.
