MCPcopy Create free account
hub / github.com/activejs/activejs / deleteIf

Method deleteIf

packages/core/src/lib/list-unit.ts:303–315  ·  view source on GitHub ↗

* Deletes items from the list-value where the predicate returns `true`. \ * Dispatches a new copy of the value, without mutating the current-value. \ * It doesn't modify the length of the list as these indices are only deleted, not removed. * * It only works if the Unit is not fr

(predicate: (item: Item, index: number) => boolean)

Source from the content-addressed store, hash-verified

301 * @category Custom ListUnit
302 */
303 deleteIf(predicate: (item: Item, index: number) => boolean): Item[] {
304 if (this.isFrozen || typeof predicate !== 'function' || this.isEmpty) {
305 return [];
306 }
307
308 const indicesToBeDeleted = [];
309 this.value().forEach((item, index) => {
310 if (predicate(item, index)) {
311 indicesToBeDeleted.push(index);
312 }
313 });
314 return this.delete(...(indicesToBeDeleted as [number, ...number[]]));
315 }
316
317 /**
318 * Finds items of the list that have a direct child property

Callers

nothing calls this directly

Calls 4

deleteMethod · 0.95
predicateFunction · 0.85
pushMethod · 0.80
valueMethod · 0.45

Tested by

no test coverage detected