CODESCRIPT

Maps

11 entries. What each one takes, what it returns, and a working example.

mapClear(harita)

Does not return a value; removes all pairs from the map (the map is emptied in place).

harita
map
The map to empty.
NOTE

The same map object is kept, only its contents are cleared; other variables holding it see it empty too.

CODESCRIPT
m = mapNew()
mapPut(m, "a", 1)
mapClear(m)
plot(mapSize(m))

One pair is written then the map is cleared; the size 0 is plotted.

mapContains(harita, anahtar)

true if the key exists in the map, otherwise false.

harita
map
The map to check.
anahtar
any
The key whose presence is queried.
NOTE

A value being na is different from the key being absent; this function only checks whether the key exists.

CODESCRIPT
m = mapNew()
mapPut(m, "a", 1)
plot(iff(mapContains(m, "a"), 1, 0))

Since key "a" was written, it plots 1.

mapCopy(harita)

A new, independent map holding the same pairs.

harita
map
The map to copy.
NOTE

The copy is independent — writing to the copy does not affect the original. Useful for branching a new state.

CODESCRIPT
a = mapNew()
mapPut(a, "x", 1)
b = mapCopy(a)
mapPut(b, "y", 2)
plot(mapSize(a))

A new pair is added to the copy, but the original still holds one pair so its size 1 is plotted.

mapGet(harita, anahtar)

The value at the key, or na if the key is absent (or the input is not a map).

harita
map
The map to read.
anahtar
any
The key whose value is requested.
NOTE

A missing key does not raise an error, it returns na — conditions run safely over na.

CODESCRIPT
m = mapNew()
mapPut(m, "tepe", highest(high, 20))
plot(mapGet(m, "tepe"))

Stores the 20-bar highest level under the "tepe" key and reads it back to plot it.

mapKeys(harita)

An array holding the map's keys in insertion order.

harita
map
The map whose keys are requested.
NOTE

You can read the array's length with arraySize and walk its elements with the array functions.

CODESCRIPT
m = mapNew()
mapPut(m, "a", 1)
mapPut(m, "b", 2)
plot(arraySize(mapKeys(m)))

Two keys are written; the length of the key array, 2, is plotted.

mapNew()

An empty map (key→value). Keys may be text, number or boolean.

NOTE

A map holds key→value pairs; writing the same key again overwrites the old value. Values may be numbers, text, booleans or series.

CODESCRIPT
m = mapNew()
mapPut(m, "esik", 42)
plot(iff(mapContains(m, "esik"), close, open))

Creates an empty map, writes 42 under the "esik" key; since the key exists it plots close.

mapPut(harita, anahtar, değer)

The value previously held at the key, or na if the key was absent. The map is changed in place.

harita
map
The map to write into.
anahtar
any
The key to store the value under (text/number/boolean).
değer
any
The value to store.
NOTE

If the key already exists its value is updated and the old value is returned; otherwise a new pair is added and na is returned.

CODESCRIPT
m = mapNew()
onceki = mapPut(m, "k", 10)
mapPut(m, "k", 20)
plot(mapGet(m, "k"))

Writes 10 then 20 under key "k"; the previous value is na on the first write. The final value 20 is plotted.

mapPutAll(harita1, harita2)

Does not return a value; copies all pairs from map2 into map1 (colliding keys are overwritten).

harita1
map
The target map (written into).
harita2
map
The source map (read from).
NOTE

Only the target (map1) changes; the source (map2) is left unchanged.

CODESCRIPT
a = mapNew()
mapPut(a, "x", 1)
b = mapNew()
mapPut(b, "y", 2)
mapPutAll(a, b)
plot(mapSize(a))

b's pair is added to a; a now holds two pairs so the size 2 is plotted.

mapRemove(harita, anahtar)

The value of the removed key, or na if the key was absent. The map is changed in place.

harita
map
The map to remove from.
anahtar
any
The key to remove.
NOTE

If the key is absent it silently returns na with no error.

CODESCRIPT
m = mapNew()
mapPut(m, "a", 5)
mapRemove(m, "a")
plot(iff(mapContains(m, "a"), 1, 0))

Key "a" is written then removed; since it is no longer present it plots 0.

mapSize(harita)

The number of key-value pairs in the map; 0 if the input is not a map.

harita
map
The map whose size is requested.
NOTE

Returns 0 for an empty map. Writing the same key again does not increase the size.

CODESCRIPT
m = mapNew()
mapPut(m, "a", 1)
mapPut(m, "b", 2)
plot(mapSize(m))

Two distinct keys are written; the size 2 is plotted.

mapValues(harita)

An array holding the map's values in key insertion order.

harita
map
The map whose values are requested.
NOTE

For numeric values you can aggregate with array functions such as arraySum / arrayAvg.

CODESCRIPT
m = mapNew()
mapPut(m, "a", 10)
mapPut(m, "b", 20)
plot(arraySum(mapValues(m)))

Values are 10 and 20; the sum of the value array, 30, is plotted.