Reference · Maps

remove

signature
remove(list | map | null, any) -> list | map

What 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

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 str

Chaining

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
8Useful? Like it, or add to its thread below.

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