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.
remarque
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
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
| Array | Values | Comparator | Result |
|---|---|---|---|
[{x:1}, {x:2}] | [{x:1}] | (a,b) => a.x === b.x | [{x:2}] |
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 }]
Deprecated: Use