Collection members distinguish safe reads, explicit mutators, ordered snapshots, key constraints, callback order, and faulting operations instead of treating host containers as the specification.
Canonical contract
Array’s checked surface includes push, get, length, slice, join, search, sorting, higher-order methods, stack operations, insertion/removal, reversal, retain, and clear. Map provides insert/get/getOr/remove, ordered keys/values/entries snapshots, size tests, membership, update, mapValues, filter, and clear. Set provides add/remove/contains, size tests, ordered toArray, union/intersection/difference, and clear.
Public surface
Mutation requires let mut for Array push/pop/clear/reverse/insert/removeAt/sort/sortBy/retain, Map insert/remove/clear/update, and Set add/remove/clear. Read methods return Option where absence is expected. Map keys and Set elements obey recursive keyability. Free and receiver higher-order operations preserve the collection’s specified iteration order.
Observable behavior
arr.get returns None outside bounds while direct index faults. map.keys, values, and entries are snapshots in insertion order; later mutation does not alter a prior snapshot. Removing and reinserting moves a key or element to the end, while updating an existing Map value leaves order unchanged. Set algebra and sorting follow their declared value/order constraints rather than unspecified host hashing.
Current support
The compiler checks the listed Array, Map, and Set members, including their generic types, parameters, callbacks, result types, properties, and mutation requirements. Methods from the host language are not added automatically.
Constraints and exclusions
Direct out-of-range indexing, non-keyable Map or Set types, mutation through immutable bindings, callback signature mismatches, x in map, string .length, and unknown members are errors. Map and Set do not gain general equality through any collection method.
Worked example
let mut scores: Map<string, int> = Map.new()
scores.insert("ada", 10)
scores.insert("lin", 12)
let ada = scores.get("ada")
let missing = scores.get("missing")
let keys = scores.keys
print("{ada}:{missing}:{keys}")