Reference · Maps
remove
signature
remove(list | map | null, any) -> list | mapWhat it does
A new map without one key, or a new list without every item equal to a value. On a
map, remove(m, k) drops the entry under k (turned into text, as all map keys are)
and leaves the others in their order. On a list, remove(xs, x) drops each item that
== x. The original is not changed.
Examples
let user = { name: "Ann", age: 41, tmp: true }let clean = remove(user, "tmp")print(clean, user)print(remove([1, 2, 1, 3], 1))output
{ name: "Ann", age: 41 } { name: "Ann", age: 41, tmp: true }[2, 3]Edge cases
- A key that is not there changes nothing and is not an error.
- Keys are text:
remove(m, 5)drops"5". - On a list, every equal item goes, not only the first; a value not in the list changes nothing.
nullas the map is an empty map and gives{}.- On a map, an error value as the key is given back, and nothing is removed.
let m = { "5": "five", a: 1 }print(remove(m, "zz"), remove(m, 5))print(remove(["a", "b", "a"], "a"), remove([1, 2], 9))print(remove(null, "a"), remove(m, int("q")))output
{ "5": "five", a: 1 } { a: 1 }["b"] [1, 2]{} err("not an int: \"q\"")Errors
A string or a number as the first argument is a runtime error, not an error value;
for text use replace.
this one fails
print(remove("abc", "a"))output
line 1: `remove` expects a map as argument 1, got strChaining
print({ a: 1, b: 2, c: 3 } | remove("b") | keys)print([3, 1, 3, 2] | remove(3) | sort)output
["a", "c"][1, 2]See also
set, merge, filter, has, replace
Thread
Thread 0 posts
On remove(): questions, tips, corrections, and code that uses it.
No posts yet. The first one opens the thread.
Edit this page on GitHub · every example's output was made by running it (tools/refcheck.mjs) · questions on Discord or r/quillo