5592}},
{:id 15} #{{:id 15, :a2 7709, :a3 7739, :a4 7792}},
}
-Original Message-
From: clojure@googlegroups.com [mailto:clojure@googlegroups.com] On Behalf Of
GrumpyLittleTed
Sent: Thursday, April 28, 2011 6:56 PM
To: Clojure
Subject: Re: Merging two maps based on ids
Sometimes it helps
Sometimes it helps to change the structure of the data you are using
to fit the job and simplify matters. In this case it appears that you
are trying to represent a relation. However the tuples are being
represented in a non-associative structure (a list). If you represent
the relation using an
Hi,
you can construct the output sequence from your input sequences.
(defn merge-data
[data-orig data-override]
(let [override-ids (set (map :id data-override))]
(concat data-override (remove (comp override-ids :id) data-orig
If you need your output sorted you can also add a
Another option is using clojure.set, as is shown here:
https://github.com/pepijndevos/Begame/blob/master/src/begame/util.clj#L99
On Apr 26, 10:10 am, Meikel Brandmeyer m...@kotka.de wrote:
Hi,
you can construct the output sequence from your input sequences.
(defn merge-data
[data-orig
(defn merge-data [data1 data2]
(map first (partition-by :id (sort-by :id (concat data1 data2)
Since the sorting is stable (relative order is kept), we know that the first
occurrence of each id is either the existing map from data1, or the new map
from data2.
On Tue, Apr 26, 2011 at 5:34
Correction:
(concat data1 data2) should be (concat data2 data1)
On Tue, Apr 26, 2011 at 6:37 PM, Jonathan Fischer Friberg
odysso...@gmail.com wrote:
(defn merge-data [data1 data2]
(map first (partition-by :id (sort-by :id (concat data1 data2)
Since the sorting is stable (relative
)) data1
From: clojure@googlegroups.com [mailto:clojure@googlegroups.com] On
Behalf Of Jonathan Fischer Friberg
Sent: Tuesday, April 26, 2011 12:58 PM
To: clojure@googlegroups.com
Subject: Re: Merging two maps based on ids
Correction:
(concat data1 data2
Can someone help me write a merge function between two maps? My problem
is as follows:
I have original data in a map:
(def data-orig
'({:id 2 :a2 34 :a3 76 :a4 87},
{:id 3 :a2 30 :a3 38 :a4 39},
{:id 5 :a2 67 :a3 32 :a4 38},
{:id 4 :a2 10 :a3 73
Can someone help me write a merge function between two maps? My problem is
as follows:
I have original data in a map:
(def data-orig
'({:id 2 :a2 34 :a3 76 :a4 87},
{:id 3 :a2 30 :a3 38 :a4 39},
{:id 5 :a2 67 :a3 32 :a4 38},
{:id 4 :a2