Alex Dixon
1 min readJun 23, 2017

--

I’m not positive which part you’re referring to. Basically, having a map function that works on an associative data structure with keys and values is useful. Javascript does not have this. I’m picking on the map function in Javascript because it is something fairly basic. There are many other examples like it that I think make programmers’ lives unnecessarily complex when contrasted to Clojurescript.

Here’s map:

// Javascript
myObject.map((v, k) => console.log(v, k), myObject)
=> Uncaught TypeError: myObject.map is not a function
// lodash
_.map(myObject, (v, k) => console.log(k, v))
=> returns array
// lodash/fp
map((v, k) => console.log(k, v), myObject)
=> returns array
// _.mapKeys (lodash)
_.mapKeys(myObject, (v, k) => console.log(k, v))
=> returns object
// ramda
mapObjIndexed((v, k) => console.log(k, v), myObject)
=> returns object
// ImmutableJS
myObject.map((v, k) => console.log(k, v))
=> returns immutable map
// ImmutableJS in React component avoiding Immutable.Map warnings
myObject.entries().map(([k, v]) => console.log(k, v))
=> forget what this returns, isn't an Immutable Map because those generate the warnings
// Things others have suggested
Object.keys(myObject).forEach(k => console.log(k, myObject[k]))
=> Object.keys converts to array. Returns null, would require assignment to variable to obtain similar effect to map.
Object.keys(myObject).reduce(....

Clojurescript:

(map (fn [[k v]] (println k v)) my-object)

--

--