Home / Docs / Standard library / Built-in methods

remove

Release v0.4.0Edition 0.2 and later

A built-in method, resolved by the type of its receiver (spec/14 §2). Edition 0.2 and later.

Edition 0.2 and later

una
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

una
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: BitSet

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

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

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

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

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

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

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

See also

set

Cost

Time O(log n) per lookup, insertion and removal on a Map[K, V] (spec/21 §5), where:

Example

src/shop.unauna
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:

Output
desk: false

Specification

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.