Re: merge nested maps

2013-07-18 Thread Uwe Dauernheim
The implementation(s) acts a bit counter-intuitive on non-nested maps: FAIL in (deep-merge-test) (test.clj:5) expected: (= (merge {:a 1, :d 1} {:a 2, :c 1}) (deep-merge {:a 1, :d 1} {:a 2, :c 1})) actual: (not (= {:c 1, :a 2, :d 1} {:a 2, :c 1})) ERROR in (deep-merge-with-test)

Re: merge nested maps

2013-07-17 Thread Chris Gill
Thank you for finding and posting this! Been wracking my brain trying to figure out a good way to do a full map merge On Thursday, April 25, 2013 5:26:53 PM UTC-4, Stuart Sierra wrote: Here's a way to do it from the Pedestal demo source

Re: merge nested maps

2013-07-17 Thread JvJ
By the way, this is already in contrib: http://clojuredocs.org/clojure_contrib/clojure.contrib.map-utils/deep-merge-with On Wednesday, July 17, 2013 5:42:24 AM UTC-7, Chris Gill wrote: Thank you for finding and posting this! Been wracking my brain trying to figure out a good way to do a full

Re: merge nested maps

2013-04-28 Thread Gary Verhaegen
Shouldn't that docstring read If vals are not maps ? On 25 April 2013 23:26, Stuart Sierra the.stuart.sie...@gmail.com wrote: Here's a way to do it from the Pedestal demo source code: (defn deep-merge Recursively merges maps. If keys are not maps, the last value wins. [ vals] (if

Re: merge nested maps

2013-04-28 Thread Stuart Sierra
Yes. On Sun, Apr 28, 2013 at 4:55 AM, Gary Verhaegen gary.verhae...@gmail.comwrote: Shouldn't that docstring read If vals are not maps ? On 25 April 2013 23:26, Stuart Sierra the.stuart.sie...@gmail.com wrote: Here's a way to do it from the Pedestal demo source code: (defn deep-merge

merge nested maps

2013-04-25 Thread Joachim De Beule
Hi list, I was searching for an easy way to combined nested maps, e.g. as in (combine {:foo {:bar baz}} {:foo {:x y}}) = {:foo {:bar baz, :x y}} I would expect that there is some core map operation to do this, but neither merge nor unify work as they simply return {:foo {:x y}}, and I don't

Re: merge nested maps

2013-04-25 Thread Michael Gardner
On Apr 25, 2013, at 15:41 , Joachim De Beule joachim.de.be...@gmail.com wrote: I was searching for an easy way to combined nested maps, e.g. as in (combine {:foo {:bar baz}} {:foo {:x y}}) = {:foo {:bar baz, :x y}} user= (merge-with merge {:foo {:bar baz}} {:foo {:x y}}) {:foo {:x y, :bar

Re: merge nested maps

2013-04-25 Thread Cedric Greevey
Seems you want a cross between update-in and merge. Maybe something like this? (defn combine Merge maps, recursively merging nested maps whose keys collide. ([] {}) ([m] m) ([m1 m2] (reduce (fn [m1 [k2 v2]] (if-let [v1 (get m1 k2)] (if (and (map? v1)

Re: merge nested maps

2013-04-25 Thread Jorge Urdaneta
It was fun to try a naive implementation (defn combine [m1 m2] (let [mm1 (transient m1)] (do (doseq [k (keys m2)] (if (contains? m1 k) (assoc! mm1 k (conj (mm1 k) (m2 k))) (assoc! mm1 k (m2 k (persistent! mm1 On 25/04/13 16:29, Cedric

Re: merge nested maps

2013-04-25 Thread Stuart Sierra
Here's a way to do it from the Pedestal demo source codehttps://github.com/pedestal/demo/blob/17eeac7a5e50d31eb81901de465f3f1d863f2f01/hammock-cafe/src/hammock_cafe/config.clj#L37 : (defn deep-merge Recursively merges maps. If keys are not maps, the last value wins. [ vals] (if (every?