Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I merge hash-maps that are inside a collection of vectors in clojure?

Tags:

clojure

Given collection of vectors of separated hash-maps

How can I go from :

[[{:a 1} {:b 2} {:c 3}] [{:a 4} {:b 5} {:c 6}] [{:a 7} {:b 8} {:c 9}]]

To:

[[{:a 1 :b 2 :c 3}] [{:a 4 :b 5 :c 6}] [{:a 7 :b 8 :c 9}]]

Thanks you for your answers!

like image 722
leontalbot Avatar asked May 08 '13 10:05

leontalbot


1 Answers

(def coll [[{:a 1} {:b 2} {:c 3}] [{:a 4} {:b 5} {:c 6}] [{:a 7} {:b 8} {:c 9}]])

(mapv (fn [v] [(apply merge v)]) coll)
;; => [[{:a 1 :c 3 :b 2}] [{:a 4 :c 6 :b 5}] [{:a 7 :c 9 :b 8}]]
like image 81
mtyaka Avatar answered Nov 15 '22 08:11

mtyaka