Home / Docs / Standard library / Built-in methods
remove
A built-in method, resolved by the type of its receiver (spec/14 §2). Edition 0.2 and later.
Edition 0.2 and later
edit m.remove(key: K) -> Unit
where m: Map[K, V]Updates m in place, written edit m.remove(...): afterwards not m.has(key: k), and m.len shrinks by one when the key was there (spec/21 §2). On a Set, written edit s.remove(...), afterwards not s.has(item: x), in O(log n) (spec/28 §6). On a HashMap and a HashSet, the same in O(|k|) expected, amortized (spec/28 §7). On a BitSet, in O(1), and an item outside its range changes nothing (spec/28 §9).
Edition 0.5 preview
edit m.remove(key: K) -> Unit
where m: Map[K, V]
edit s.remove(item: T) -> Unit
where s: Set[T]
edit m.remove(key: K) -> Unit
where m: HashMap[K, V]
edit s.remove(item: T) -> Unit
where s: HashSet[T]
edit b.remove(item: Int) -> Unit
where b: BitSetUpdates m in place, written edit m.remove(...): afterwards not m.has(key: k), and m.len shrinks by one when the key was there (spec/21 §2). On a Set, written edit s.remove(...), afterwards not s.has(item: x), in O(log n) (spec/28 §6). On a HashMap and a HashSet, the same in O(|k|) expected, amortized (spec/28 §7). On a BitSet, in O(1), and an item outside its range changes nothing (spec/28 §9).
In editions 0.5. In edition 0.2, 0.3, 0.4: no Set[T], HashMap[K, V], HashSet[T] or BitSet receiver, since std.collections begins in edition 0.5: it has none of edit s.remove(item: T) -> Unit, where s: Set[T], where m: HashMap[K, V], where s: HashSet[T], edit b.remove(item: Int) -> Unit and where b: BitSet.
On a Map[K, V]
The receiver is the map m, changed in place, written edit m.remove(...).
Parameters
key: the key; from edition 0.3, it is taken at the base type of a refined key typeK, so a key outside the refinement finds no entry
Returns
Unit: nothing; afterwards m.has(key: key) is false, and m.len shrinks by one when key was there.
On a Set[T]
The receiver is the set s, changed in place, written edit s.remove(...).
Parameters
item: the item; it is taken at the base type of a refined item typeT, so an item outside the refinement is not found
Returns
Unit: nothing; afterwards s.has(item: item) is false, and s.len shrinks by one when item was there.
On a HashMap[K, V]
The receiver is the hash map m, changed in place, written edit m.remove(...).
Parameters
key: the key; it is taken at the base type of a refined key typeK, so a key outside the refinement finds no entry
Returns
Unit: nothing; afterwards m.has(key: key) is false, and m.len shrinks by one when key was there.
On a HashSet[T]
The receiver is the hash set s, changed in place, written edit s.remove(...).
Parameters
item: the item; it is taken at the base type of a refined item typeT, so an item outside the refinement is not found
Returns
Unit: nothing; afterwards s.has(item: item) is false, and s.len shrinks by one when item was there.
On a BitSet
The receiver is the bit set b, changed in place, written edit b.remove(...).
Parameters
item: the integer; outside the range from 0 tob.size - 1it changes nothing
Returns
Unit: nothing; afterwards b.has(item: item) is false, b.size is unchanged, and b.len shrinks by one when item was a member.
Use instead
withoutfor a new map, leaving the old one as it is
See also
Cost
Time O(log n) per lookup, insertion and removal on a Map[K, V] (spec/21 §5), where:
n: the number of entries inm; in the native runtime the update is in place whenmis uniquely held, and on a copy, in O(n), otherwise
Example
module shop
--- An item taken out of the range.
pub main() -> Unit
uses @console: Console[print]
=
let edit stock = empty_map().with(key: "lamp", value: 3).with(key: "desk", value: 1)
edit stock.remove(key: "desk")
let desk = stock.has(key: "desk")
@console.print("desk: {desk}")una run . prints:
desk: falseSpecification
- spec/21 §2
spec/28 §6spec/28 §7spec/28 §9
Generated from una v0.4.0 (docs/std/builtins.json, which is not part of the specification): built-in methods have no declaration, so una writes these signature lines and tests each against its checker. The specification governs: spec/14 §2.