Re: Is there a better way to do this than reduce + nested map?

2015-09-14 Thread Nicolás Berger
There is clojure.set/join to do exactly what you are asking for: ``` (-> (clojure.set/join entities locations) (clojure.set/rename {:id :location})) ;=> ({:name "bar", :location 101} {:name "foo", :location 100}) ``` (I'm also using clojure.set/rename to rename :id to :location) http://cloju

Re: Is there a better way to do this than reduce + nested map?

2015-09-13 Thread Colin Yates
You’re right, I missed a step :-). Something like (typed in-line so it really won’t compile): :locations [{“us” 100} {“de” 101}] :locations-seq (into {} (map (fn [{:keys [location]}] [:location (get locations location)])…) ;; the above produces a sequence symmetrical with entities, each map cont

Re: Is there a better way to do this than reduce + nested map?

2015-09-13 Thread Brian Platz
Not sure I follow Colin's suggestion entirely, but his suggestion led me to this which is better. I'd still love any other suggestions to improve! (def entities [{:name "foo" :location "us"} {:name "bar" :location "de"}]) (def locations [{:location "us" :id 100} {:location "de" :id 101}]) ;; mak

Re: Is there a better way to do this than reduce + nested map?

2015-09-13 Thread Colin Yates
I would transform the locations into {location id} and then use merge. > On 13 Sep 2015, at 3:14 PM, Brian Platz wrote: > > I have a pattern that comes up frequently, when I need to merge some value > into one map list from matching keys in a second map list. > > I've developed a way to handle

Re: Is there a better way to do this

2012-06-17 Thread Joao_Salcedo
Hi Sean, That works just perfect !!! JS On Saturday, June 16, 2012 11:58:30 AM UTC+10, Sean Corfield wrote: > > On Fri, Jun 15, 2012 at 7:30 AM, Baishampayan Ghose > wrote: > > This is how it should be done, really - > > > > (defn get-events-hlpr > > "Retrieves events from MongoDB." > >

Re: Is there a better way to do this

2012-06-17 Thread Joao_Salcedo
Hi ALL, Thanks that is exactly what i was looking for :) On Saturday, June 16, 2012 12:30:45 AM UTC+10, Baishampayan Ghose wrote: > > > Hi Baishampayan, > > > >> (defn get-events-hlpr [] > >> "Retrieves events from MongoDB." > >> (vec (mc/find-maps "events"))) > > > > Is that Emacs Lisp

Re: Is there a better way to do this

2012-06-15 Thread Sean Corfield
On Fri, Jun 15, 2012 at 7:30 AM, Baishampayan Ghose wrote: > This is how it should be done, really - > > (defn get-events-hlpr >  "Retrieves events from MongoDB." >  [] >  (vec (map #(dissoc :_id %) (mc/find-maps "events" ;; remove the :_id as > well Or in Clojure 1.4.0 and later: (defn get

Re: Is there a better way to do this

2012-06-15 Thread Baishampayan Ghose
> Hi Baishampayan, > >> (defn get-events-hlpr [] >>   "Retrieves events from MongoDB." >>   (vec (mc/find-maps "events"))) > > Is that Emacs Lisp or Common Lisp? > > Bye, > Tassilo > > Just nitpicking that you adapted the OP's error of adding the docstring > after the parameter vector. ;-) You are

Re: Is there a better way to do this

2012-06-15 Thread Tassilo Horn
Baishampayan Ghose writes: Hi Baishampayan, > (defn get-events-hlpr [] > "Retrieves events from MongoDB." > (vec (mc/find-maps "events"))) Is that Emacs Lisp or Common Lisp? Bye, Tassilo Just nitpicking that you adapted the OP's error of adding the docstring after the parameter vector. ;-

Re: Is there a better way to do this

2012-06-15 Thread Baishampayan Ghose
> I am receiving a sequence from a particular function so I want to get that > sequence and converted to a vector o I can return a vector instead. > > (defn get-events-hlpr [] > "Retrieves events from MongoDB." > (init) > (def items (mc/find-maps "events")) ;; get the sequence > (loop [vtr [] >   d

Re: Is there a better way to do this

2012-06-15 Thread Walter Tetzner
> You could just do (vec (mc/find-maps "events")). > Also, to dissoc :_id from each item, do (vec (map #(dissoc % :_id) (mc/find-maps "events"))). -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googleg

Re: Is there a better way to do this

2012-06-15 Thread Walter Tetzner
On Friday, June 15, 2012 9:54:37 AM UTC-4, Joao_Salcedo wrote: > Is the right way? > You could just do (vec (mc/find-maps "events")). Also, using def creates a top-level var. You probably wanted (let [items (mc/find-maps "events")] ...) instead. -- You received this message because you are s