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"})

1 Answer 1

1
(map (fn [[k v]]
       (into {} [[:ID k]
                 [:CREDIT (apply str (interpose ", " (distinct (map :CREDIT v))))]]))
     (group-by :ID data))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.