Skip to content

09 · Data Structures

Explicit map types

Write a map type as #{K: V}. Braces with named fields always describe a record type, including fields named int or String. Empty braces are an empty record. Map<K, V> remains supported.

On this page

Write a map type as #{K: V}. Braces with named fields always describe a record type, including fields named int or String. Empty braces are an empty record. Map<K, V> remains supported.

Complete example

Explicit map types.

21-explicit-map-types.zolo
Playground
// Map types and map values use the same explicit delimiter.

let counts: #{str: int} = #{ ok: 2, failed: 1 }
print(counts["ok"])
// expected: 2


// Field labels never turn a record annotation into a map.

let row: { str: int, User: str, type: bool } = #{ str: 7, User: "Ada", type: true }
print(row.str)
// expected: 7

print(row.User)
// expected: Ada

print(row.type)
// expected: true


type Lookup = #{str: [#{int: str}]}
let nested: Lookup = #{ first: [#{ [1]: "one" }] }
print(nested["first"][0][1])
// expected: one

Rules and behavior

Records, maps and updates · Documentation

From a checkout of the repository:

zolo examples/features/06-data-structures/21-explicit-map-types.zolo

Global index

Find your way through Zolo

Try an idea

Start here

9 results

9 results

enespt-br