Merging maps based on custom priority logic

2011-12-25 Thread Shoeb Bhinderwala
I want to merge lists of maps. Each map entry has an :id and :code key. The code associated to :id from one map should have higher precedence than the same :id entry from another map. I have an implementation. The problem and solution is best described using example: ;priority 1 map (def p1

Re: Merging maps based on custom priority logic

2011-12-25 Thread Bill Caputo
On Sun, Dec 25, 2011 at 10:25 AM, Shoeb Bhinderwala shoeb.bhinderw...@gmail.com wrote: I want to merge lists of maps. Each map entry I have written the implementation. [...] Is there a more efficient, cleaner and idiomatic way to do this. Am I missing out on any core library functions that

Re: Merging maps based on custom priority logic

2011-12-25 Thread Baishampayan Ghose
Is there a more efficient, cleaner and idiomatic way to do this. Am I missing out on any core library functions that already provide this behavior? I believe the core function merge-with may give you what you are looking for:

Re: Merging maps based on custom priority logic

2011-12-25 Thread Bill Caputo
On Sun, Dec 25, 2011 at 10:37 AM, Baishampayan Ghose b.gh...@gmail.com wrote: Shoeb wants to merge sequences of maps and not the maps themselves, so merge/merge-with won't help him much. Sorry, I may have misunderstood, I was thinking something like this (where select-code implements his

Re: Merging maps based on custom priority logic

2011-12-25 Thread Meikel Brandmeyer
Hi, maybe using group-by works? (defn custom-merge [maps] (- maps (apply concat) (group-by :id) (sort-by key) (map (comp first val I'm not sure about the efficiency, though. If you don't need the result sorted by :id you might replace the sort and the map by “vals (map