Pudu programming language
Menu
API reference

Std.MultiMap.MultiMap

1 declaration

type

MultiMap

This declaration introduces a public type.

What it does

A map holding several values under one key.

Grouping is the commonest thing anyone does with a map, and Map.groupBy

already builds one. What it does not do is keep one: adding a value to a

key that may or may not already be there, taking one occurrence back out,

and having the key stop existing when its last value goes.

Written by hand that is the same three lines every time — match the key, push

onto what is there or start an array — plus a fourth that is the one people

forget: removing the key once its values run out. A key left mapped to an

empty array is a key containsKey then answers true for and get answers

nothing for, which is a map disagreeing with itself.

So the rule here is that a key with no values does not exist. Every

operation maintains it, and it is what makes size, containsKey and

keys mean what a reader expects.

Values under a key keep the order they were added in. Duplicates are kept:

this is a bag under each key, not a set, because the commonest use is

collecting records that genuinely repeat — two log lines at the same level,

two headers with the same name.

Read the signature

  • This declaration has no value signature because it introduces a type or trait.

Back to Std.MultiMapSearch related declarations