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() } } log(observation) |
|
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. |
observation.weather := 'Raining' log(observation) |
|
cloned := clone(observation) |
We can iterate through the keys by calling |
each(keys(observation), (key) => ( log(observation.(key)) )) |
$ ink maps.ink {weather: 'Sunny', observedAt: {time: 1626466495.22846460}} {weather: 'Raining', observedAt: {time: 1626466495.22846460}} Raining {time: 1626466495.22846460} |
Next example: Functions.