* 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)
| 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 |