Home / Docs / Standard library / Built-in methods

update

Release v0.4.0Edition 0.5 preview

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

una
edit m.update(key: K, initial: V, change: fn(V) -> V) -> Unit
  where m: Map[K, V]
edit m.update(key: K, initial: V, change: fn(V) -> V) -> Unit
  where m: HashMap[K, V]

Updates m in place, written edit m.update(...): sets key to change(v), where v is its value, or initial when m has no key. change is called exactly once, and when it fails, m keeps its value from before the call (spec/21 §2). On a HashMap, the same in O(|k|) expected, amortized (spec/28 §7).

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.