SplitScript reference / Map<K, V> / insert

Map<K, V>.insert

Method

Map<K, V>.insert(key: K, value: V) -> bool where K: Equatable

Inserts a key-value pair or replaces the value for an existing key.

Returns true when a new key was inserted and false when an existing entry was replaced. Replacement preserves insertion order.

Parameters

  • key: Key to insert or replace.
  • value: Value to store for the key.

Effects: allocates, mutates the receiver

Runtime behavior: available everywhere; synchronous

Examples

Distinguish insertion from replacement

let routes = Map.new<String, u32>()
let inserted = routes.insert("Atrium", 12)
let replaced = routes.insert("Atrium", 14)