Skip to main content

pullAllWith()

pullAllWith<T>(array, values, comparator): T[]

Removes all given values from array using a comparator function for equality.

DEPRECATED

Use differenceWith instead for immutable operations.

Reason:
Pithos design philosophy always favors immutability.

note

Mutates the array in place.


Type Parametersโ€‹

T: Tโ€‹

The type of elements in the array.


Parametersโ€‹

array: T[]โ€‹

The array to modify.

values: readonly T[]โ€‹

The values to remove.

comparator: (a, b) => booleanโ€‹

The function invoked to compare elements.


Returns: T[]โ€‹

The mutated array.


See Alsoโ€‹

differenceWith


Sinceโ€‹

2.0.0


Also known asโ€‹

pullAllWith (Lodash, es-toolkit) ยท โŒ (Remeda, Radashi, Ramda, Effect, Modern Dash, Antfu)


Exampleโ€‹

// โŒ Deprecated approach (mutates array)
const array = [{ x: 1, y: 2 }, { x: 3, y: 4 }, { x: 5, y: 6 }];
pullAllWith(array, [{ x: 3, y: 4 }], (a, b) => a.x === b.x && a.y === b.y);
console.log(array); // [{ x: 1, y: 2 }, { x: 5, y: 6 }]

// โœ… Recommended approach (immutable)
const array = [{ x: 1, y: 2 }, { x: 3, y: 4 }, { x: 5, y: 6 }];
const result = differenceWith(array, [{ x: 3, y: 4 }], (a, b) => a.x === b.x && a.y === b.y);
console.log(result); // [{ x: 1, y: 2 }, { x: 5, y: 6 }]
console.log(array); // unchanged

How it works?โ€‹

Removes values from array using a comparator function (mutates).

Mutation Flowโ€‹

Common Inputsโ€‹

ArrayValuesComparatorResult
[{x:1}, {x:2}][{x:1}](a,b) => a.x === b.x[{x:2}]

warning Deprecated: Use differenceWith() from Arkhe for immutable operations.


Use Casesโ€‹

Remove with custom comparator ๐Ÿ“Œโ€‹

Remove values using custom equality comparison.

const users = [{ id: 1 }, { id: 2 }, { id: 3 }];
const toRemove = [{ id: 2 }];
const result = users.filter(u =>
!toRemove.some(r => r.id === u.id)
);
// [{ id: 1 }, { id: 3 }]

Filter by propertyโ€‹

Remove objects matching specific criteria.

const products = [
{ sku: 'A1', stock: 0 },
{ sku: 'B2', stock: 5 },
{ sku: 'C3', stock: 0 }
];
const outOfStock = products.filter(p => p.stock > 0);
// [{ sku: 'B2', stock: 5 }]