MCPcopy Index your code
hub / github.com/immutable-js/immutable-js / remove

Function remove

src/functional/remove.ts:36–71  ·  view source on GitHub ↗
(
  collection:
    | Collection<K, unknown>
    | Array<unknown>
    | { [key: PropertyKey]: unknown },
  key: K
)

Source from the content-addressed store, hash-verified

34 | { [key: PropertyKey]: unknown },
35>(collection: C, key: K): C;
36export function remove<K>(
37 collection:
38 | Collection<K, unknown>
39 | Array<unknown>
40 | { [key: PropertyKey]: unknown },
41 key: K
42) {
43 if (!isDataStructure(collection)) {
44 throw new TypeError(
45 'Cannot update non-data-structure value: ' + collection
46 );
47 }
48 if (isImmutable(collection)) {
49 // @ts-expect-error weird "remove" here,
50 if (!collection.remove) {
51 throw new TypeError(
52 'Cannot update immutable value without .remove() method: ' + collection
53 );
54 }
55 // @ts-expect-error weird "remove" here,
56 return collection.remove(key);
57 }
58 // @ts-expect-error assert that key is a string, a number or a symbol here
59 if (!hasOwnProperty.call(collection, key)) {
60 return collection;
61 }
62 const collectionCopy = shallowCopy(collection);
63 if (Array.isArray(collectionCopy)) {
64 // @ts-expect-error assert that key is a number here
65 collectionCopy.splice(key, 1);
66 } else {
67 // @ts-expect-error assert that key is a string, a number or a symbol here
68 delete collectionCopy[key];
69 }
70 return collectionCopy;
71}

Callers 4

updateInDeeplyFunction · 0.90
list.tsFile · 0.85
functional.tsFile · 0.85
remove.tsFile · 0.85

Calls 5

isImmutableFunction · 0.90
isDataStructureFunction · 0.85
shallowCopyFunction · 0.85
spliceMethod · 0.80
removeMethod · 0.65

Tested by

no test coverage detected