Sunday, June 14, 2015

Combining Maps in JavaScript and Clojure

"Thy knotted and combined locks to part,
And each particular hair to stand an end
Like quills upon the fretful porpentine.
"-- Shakespeare, Hamlet
Act I, Scene V, Lines 18-20


Sometimes in life you want to combine different things together to make something that is even better than the things by themselves.

"Within the same school, the idea was that
We'd later combine both styles, unify the techniques
But still, we were too young
Too full of ignorant pride in our own succulent sorrow
-- Rancid, Crane Fist


In Lodash we can use the Merge and Assign functions to combine Map Data Structures.

In the code above we see the big difference, based on the examples given, between Merge and Assign is around combining the internal Map Data Structures.  We see that the result from Merge will combine them together whereas Assign will just overwrite them.


Clojure also has a Merge function.

In the code above we see that merge in Clojure works like Assign in Lodash but we can use merge-wtih along with conj to get the similar results to Merge in Lodash.


"As all things come to an end, even this story."
-- J. R. R. Tolkien, The Hobbit