← index

Mapsealed

inherits Object · mixes in Iterate

The insertion-ordered dictionary, written #{'a': 1 'b': 2}. Any value can be a key, and iteration, printing, and serialization keep the order entries were added — a parse → generate round-trip doesn't reshuffle a document.

Scalars, strings, and other content values key by value; a user instance keys by identity unless its class overrides both hash and ==: (its hash runs once, at insert); the mutable built-in collections key by identity. Reading an absent key answers nil. A map with a checked value type comes from Map.of: / ensure:.

extended at core/02-iterate.qn:557

Maps are iterable: the iteration element is a key/value pair.

Class methods

default

A fresh empty Map, the Map class default.

core/02-iterate.qn:562

fromPairs:

A Map built from an iterable of KeyValuePairs (as produced by iterating a Map), in iteration order.

Map.fromPairs:(#{'a': 1 'b': 2}.list.select:{ |p| p.value > 1 })    "* -> #{'b': 2}

core/02-iterate.qn:570

new

A fresh empty map — the same value the #{} literal builds.

native

new:

Always refused: a Map has no instance fields for a new: config block to set. Construct with #{}, Map.new, or Map.of:.

native

of:

A fresh empty map tagged with a VALUE class: every later at:put: checks the value (keys stay unrestricted), raising a catchable TypeError on a mismatch.

(Map.of:Integer).at:'n' put:1     "* -> #{'n': 1}

native

Instance methods

==:

Entry-wise equality: true when the other value is a Map of the same size holding, for every key here, an == value there — insertion order does not matter. Anything that is not a Map answers false.

#{'a': 1 'b': 2} == #{'b': 2 'a': 1}     "* -> true

native

at:

The value stored under a key, or nil when the key is absent (use containsKey?: to tell the two apart).

#{'a': 1 'b': 2}.at:'a'     "* -> 1

native

at: put:

Store a value under a key — replacing what an existing key holds, appending a new entry (last in iteration order) otherwise. Answers the receiver. On a tagged map (Map.of:) the value is checked first.

#{'a': 1}.at:'b' put:2     "* -> #{'a': 1 'b': 2}

native

bind:

Destructure into a block: each parameter is looked up as a key — the parameter's name as a String key first, then as a Symbol key — and an absent key binds nil. Answers the block's value.

#{'w': 3 'h': 4}.bind:{ |w h| w * h }     "* -> 12

native

containsKey?:

True when the key is present — the way to tell a stored nil from an absent key (at: answers nil for both).

#{'a': 1}.containsKey?:'a'     "* -> true

native

count

The number of entries.

#{'a': 1 'b': 2}.count     "* -> 2

native

each:Block

Iterate in insertion order (the Map preserves it). The iteration element is a key/value PAIR, not the value type (GENERICS_ARCH 4.4).

core/02-iterate.qn:575

elementType

The checked VALUE type as a Symbol, or nil for an ordinary untagged map.

(Map.of:Integer).elementType     "* -> Integer

native

emptyLike

A fresh empty map like the receiver — value tag included. The species hook the Iterate mixin uses, so transforms of a checked map stay checked.

native

ensure:

Check every value against a class and answer a NEW map carrying that value tag; a non-matching value raises a catchable TypeError naming the offending key's class. The receiver itself stays untagged.

native

keys

The keys as a List, in insertion order.

#{'a': 1 'b': 2}.keys     "* -> #(a b)

native

remove:

Remove a key's entry, answering the removed value — or nil (removing nothing) when the key is absent. The remaining entries keep their order.

#{'a': 1 'b': 2}.remove:'a'     "* -> 1

native

values

The values as a List, in insertion order (index-aligned with keys).

#{'a': 1 'b': 2}.values     "* -> #(1 2)

native