Home / Docs / Standard library / Built-in methods
without
A built-in method, resolved by the type of its receiver (spec/14 §2). Edition 0.2 and later.
Edition 0.2 and later
m.without(key: K) -> Map[K, V]
where m: Map[K, V]A map with the contract of remove, for the result (spec/21 §2). On a Set, a set with the contract of remove, for the result (spec/28 §6); on a HashMap and a HashSet, the same for the hash table (spec/28 §7); on a BitSet, the same for the bit set (spec/28 §9).
Edition 0.5 preview
m.without(key: K) -> Map[K, V]
where m: Map[K, V]
s.without(item: T) -> Set[T]
where s: Set[T]
m.without(key: K) -> HashMap[K, V]
where m: HashMap[K, V]
s.without(item: T) -> HashSet[T]
where s: HashSet[T]
b.without(item: Int) -> BitSet
where b: BitSetA map with the contract of remove, for the result (spec/21 §2). On a Set, a set with the contract of remove, for the result (spec/28 §6); on a HashMap and a HashSet, the same for the hash table (spec/28 §7); on a BitSet, the same for the bit set (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 s.without(item: T) -> Set[T], where s: Set[T], m.without(key: K) -> HashMap[K, V], where m: HashMap[K, V], s.without(item: T) -> HashSet[T], where s: HashSet[T], b.without(item: Int) -> BitSet and where b: BitSet.
On a Map[K, V]
The receiver is the map m.
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
Map[K, V]: a map with the contract of remove for the result: m without key; m itself is unchanged.
On a Set[T]
The receiver is the set s.
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
Set[T]: a set with the contract of remove for the result: s without item; s itself is unchanged.
On a HashMap[K, V]
The receiver is the hash map m.
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
HashMap[K, V]: a map with the contract of remove for the result: m without key; m itself is unchanged.
On a HashSet[T]
The receiver is the hash set s.
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
HashSet[T]: a set with the contract of remove for the result: s without item; s itself is unchanged.
On a BitSet
The receiver is the bit set b.
Parameters
item: the integer; outside the range from 0 tob.size - 1it changes nothing
Returns
BitSet: a bit set with the contract of remove for the result: b without item, of the same size; b itself is unchanged.
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; the update is in place when the call is the last use ofmand nothing else holds it, and on a copy, in O(n), otherwise
Example
module shop
--- A price list without one item, and the list it came from.
pub main() -> Unit
uses @console: Console[print]
=
let stock = empty_map().with(key: "lamp", value: 3).with(key: "desk", value: 1)
let fewer = stock.without(key: "desk")
@console.print("{fewer.len} of {stock.len}")una run . prints:
1 of 2Specification
- 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.