1

So I have the below hash map of k/v:

(def data [{:ID "0000010890" :CREDIT "EM 1"}

{:ID "0000010890" :CREDIT "FLOW 1"}

{:ID "0000010890" :CREDIT "EM 1"}

{:ID "0000010890" :CREDIT "FLOW 1"}

{:ID "0000010809" :CREDIT "FLOW 1"}])

which I need to merge in to this:

[{:ID "0000010890" :CREDIT "EM 1, FLOW 1"}

{:ID "0000010809" :CREDIT "FLOW 1"}]

Can anyone advise the best way to go about this in clojure?

My attempt:

(defn- create-issue-summary-2 [data]
            (->> data
                 (group-by :ID)
                 (map (fn [[k v]] (into {:ID k} (apply merge-with (map #(dissoc % :ID) v)))))))

Which results in

({:ID "0000010890", :CREDIT "FLOW 1"} 

{:ID "0000010809"})

4

1 回答 1

1
(map (fn [[k v]]
       (into {} [[:ID k]
                 [:CREDIT (apply str (interpose ", " (distinct (map :CREDIT v))))]]))
     (group-by :ID data))
于 2013-04-26T12:38:42.903 回答