Ink by Example: Maps

Like lists, maps use the composite value — Ink's single built-in data structure. At runtime, maps are hashmaps with string keys.

std := load('../vendor/std')
clone := std.clone
each := std.each
log := std.log

observation := {
    weather: 'Sunny'
    'observedAt': {
        time: time()

Like lists, we use the dot syntax to access and mutate.

observation.('weather') := 'Raining'

If we know the key before runtime, we can use a shortcut and just write it out. := 'Raining'

std.clone can be used to create a copy of a map.

cloned := clone(observation)

We can iterate through the keys by calling keys.

each(keys(observation), (key) => (

$ ink
{weather: 'Sunny', observedAt: {time: 1599459668.32206416}}
{weather: 'Raining', observedAt: {time: 1599459668.32206416}}
{time: 1599459668.32206416}

Next example: Functions.