Skip to main content

Maps

The video for “Maps” is in the works!

Maps store key-value pairs, allowing fast lookup by key.

Creating Maps

Try it yourself
Loading...

Empty Maps

An empty map is written {:}, not {}. Braces on their own are the empty set, so the colon is what tells the two apart. An empty map also needs an explicit type, since there are no entries to infer the key and value types from.

Try it yourself
Loading...

Writing {} where a map is expected is a compile error that points you at {:}.

Accessing Values

Try it yourself
Loading...

Modifying Maps

Try it yourself
Loading...

Map Methods

Try it yourself
Loading...

Previous: Lists | Next: Sets