I wanted to merge ArrayMap in a vector. Is there a way to do that?
I put this together but wondering it there's already a library for
that.
(defn merge-by-field
"xt must have field vals unique"
[xs xt field]
(let [fmerge (fn [id s]
(merge s (first (filter #(= id (val (find % field)))
xt))))]
(for [i xs]
(fmerge (field i) i))))
(def e1 [{:a 1 :b "b" :c 300 }{:a 2 :b "a" :c 500 }])
(def e2 [{:a 1 :d "blah"}{:a 2 :d "blah2"}])
(merge-by-field e1 e2 :a)
output:
({:d "blah", :a 1, :b "b", :c 300} {:d "blah2", :a 2, :b "a", :c 500})
On May 10, 9:31 am, Jonathan Fischer Friberg <[email protected]>
wrote:
> use (merge e1 e2)
>
> Jonathan
>
>
>
> On Tue, May 10, 2011 at 6:11 PM, clj123123 <[email protected]> wrote:
> > (def e1 {:a 1 :b "b" :c 300 })
> > (def e2 {:a1 :d "blah"})
>
> > how to merge to get that?
>
> > {:a 1 :b "b" :c 300 :d "blah"}
>
> > also is there a way to merge if the ArrayMap was in a vector?
>
> > Thanks.
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Clojure" group.
> > To post to this group, send email to [email protected]
> > Note that posts from new members are moderated - please be patient with
> > your first post.
> > To unsubscribe from this group, send email to
> > [email protected]
> > For more options, visit this group at
> >http://groups.google.com/group/clojure?hl=en- Hide quoted text -
>
> - Show quoted text -
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en