---
title: "remove"
url: https://una-lang.org/en/docs/std/builtin/remove/
release: v0.4.0
edition: "0.2 and later"
source: https://github.com/una-lang/una/blob/v0.4.0/docs/std/builtins.json
---

# remove

A built-in method, resolved by the type of its receiver ([`spec/14 §2`](https://una-lang.org/en/docs/spec/14-standard-library/#s2)). 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

- `key`: the key\; from edition 0\.3\, it is taken at the base type of a refined key type `K`\, 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 type `T`\, 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 type `K`\, 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 type `T`\, 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 to `b.size - 1` it 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

- [`without`](https://una-lang.org/en/docs/std/builtin/without/) for a new map\, leaving the old one as it is

## See also

[`set`](https://una-lang.org/en/docs/std/builtin/set/)

## Cost

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

- `n`: the number of entries in `m`\; in the native runtime the update is in place when `m` is uniquely held\, and on a copy\, in O\(n\)\, otherwise

## Example

`src/shop.una`

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

```text
desk: false
```

## Specification

- [`spec/21 §2`](https://una-lang.org/en/docs/spec/21-maps/#s2)
- `spec/28 §6`
- `spec/28 §7`
- `spec/28 §9`

Generated from una v0.4.0 ([`docs/std/builtins.json`](https://github.com/una-lang/una/blob/5fec93d88932b333feec25e589355a2cb34c37b5/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`](https://una-lang.org/en/docs/spec/14-standard-library/#s2).
