Designing a MultiMap (in DOM, would like to be consistent with ES)

Kris Kowal kris.kowal at cixar.com
Fri Nov 30 16:07:54 PST 2012


Perhaps consider .push(key, …values) instead of .append(key, value)
and .appendAll(key, values).

I’ve seen this kind of MultiMap around, so I presume people like the
heterogenous range type. I’ve gone a different way in my work, where
MultiMap was a Map that would set the value for a missing key to an
empty array. Then, extended Array to have a "one" or "only" method.

getAll(key) ~ get(key)
get(key) ~ get(key).one()
setAll(key, values) ~ set(key, values)
set(key, value) ~ set(key, [value])
append(key, value) ~ get(key).push(value)
appendAll(key, values) ~ get(key).push(...values)

For the URL use case, this loses information about interleaving of
keys, which is usually unimportant except (perhaps) in making round
trips between parse and stringify.

Kris Kowal


More information about the es-discuss mailing list