#1055·ramda

support Map

Author: davidchambersCreated Apr 29, 2015Updated Oct 22, 2024
Labelsproposal1.0 discussion

For 20 years JavaScript programmers have been using objects as maps. In some environments we now have the option of using Map which saves us from worrying about inherited properties and allows us to use values other than strings as keys. We could even think of objects as "map-like", in that they're an acceptable substitute for a limited set of use cases.

It would be nice to support real maps in Ramda. We could have a second version of each "object" function, or we could switch based on argument type. This is an option we've avoided in the past, but it may be justified in this case. We're not attempting to unify String and Array or Array and Object.

The switch would look something like this:

javascript
if (typeof Map === 'function' && x instanceof Map) {
  // Map logic
} else {
  // Object logic
}

R.assoc, for example, would then have the following types:

R.assoc :: String -> a -> {String: a} -> {String: a}
        :: a -> b -> Map a b -> Map a b

This issue was prompted by discussion in plaid/sanctuary#24 and plaid/sanctuary#25.