Skip to content
Open Saka

Maps

A Map key -> value pairs two Values:

"pen" -> 12 // {"pen" -> 12}

A Map is a Record with the fields k and v, and the REPL shows it that way: (k: "pen", v: 12).

("pen" -> 12).v // {12}

Read the key with .k:

("pen" -> 12).k // {"pen"}

In a Bag of Maps, keys can repeat, and each Map keeps its own value:

{"pen" -> 2, "pen" -> 3, "book" -> 5}
// {"book" -> 5, "pen" -> 2, "pen" -> 3}

The same Map can repeat too, just like any other Value in a Bag.

>> reads the values of every Map with a matching key:

"pen" >> {"pen" -> 2, "pen" -> 3, "book" -> 5} // {2, 3}

When no key matches, the result is an empty Bag:

"pencil" >> {"pen" -> 2, "book" -> 5} // int:{2, 5}:{}

<< reads the keys of every Map with a matching value:

{"pen" -> 2, "book" -> 5, "card" -> 2} << 2 // {"card", "pen"}

Each matching pair contributes to the result, so repeats count:

"pen"'2 >> {"pen" -> 2} // {2'2}

-- joins Maps where the first value matches the second key:

{"pen" -> "stationery", "book" -> "reading"}
-- {"stationery" -> 2, "reading" -> 5}
// {"book" -> 5, "pen" -> 2}

reverse swaps each Map’s key and value:

reverse({"pen" -> 2, "book" -> 5}) // {2 -> "pen", 5 -> "book"}

Pipeline operators build Maps from other data. Grouping and summarizing changes their values and groups repeated keys.

Next, describe which Values a Bag may hold with Sets.