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
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
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
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
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 it, but I think it could be better. Here is
a simple example of it:
In the below case, we are looking to replace the :location in
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."
> >
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
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
> 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
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. ;-
> 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
> 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
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
HI All,
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 []
data it
Ok so there are two use cases:
1) testing constraint
2) referencing a snapshot
And two operations
A) @
B) ensure
1A is incorrect
1B is correct
2A is correct and concurrent
2B is correct but not concurrent
"More concurrency" is the default. This increases the chance of
incorrectness due to progr
> And even then, ensure is often not needed and overkill. Make sure you
> have a real business requirement that the predicate remain true (or
> value fixed) on transaction completion. We need to move to a world in
--
It seems that my problem falls exactly in this category. Ensuring
*
On Wed, Sep 23, 2009 at 10:17 AM, Christophe Grand
wrote:
>
>
> On Wed, Sep 23, 2009 at 7:14 AM, Timothy Pratley
> wrote:
>>
>> When it useful to be able to deref inside a dosync without ensuring?
>
>
> In a read-only transaction.
>
>
>>
>> Ensure seems like a more safe default of what I'd expec
On Wed, Sep 23, 2009 at 7:14 AM, Timothy Pratley
wrote:
> When it useful to be able to deref inside a dosync without ensuring?
>
In a read-only transaction.
> Ensure seems like a more safe default of what I'd expect from a
> transaction. So why not make deref automatically ensure within a
> d
On Sep 23, 9:23 am, Dave Jack wrote:
> Maybe @ should expand to ensure rather
> than deref inside a transaction, instead?
Should've thought about this more. How is the reader supposed to know
that this code is called in a transaction? And it would leak if you
deref'd inside a function called a
> When it useful to be able to deref inside a dosync without ensuring?
When you deref and alter/set the same ref, the ref is protected from
modification as well.
I couldn't think of an example of what I think you had in mind,
something that requires a transaction but is tolerant of modification
o
> You need to prevent the modification of consuming by using ensure
> rather than deref (@).
Oh - excellent point! I didn't think of that.
When it useful to be able to deref inside a dosync without ensuring?
Ensure seems like a more safe default of what I'd expect from a
transaction. So why not
>> .. It waits until the value is actually needed. For
> more details on this, see http://ociweb.com/mark/stm/article.html.
.
Great article.Thanks !
Roger
>
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "Clojur
> How can I be sure that no more data is added to data after @consuming
> was set to true ?
You need to prevent the modification of consuming by using ensure
rather than deref (@).
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the
On Tue, Sep 22, 2009 at 3:18 PM, Roger Gilliar wrote:
>
>> thanks a lot. Your code looks much better than mine. But there is one
>> part that I don't understand:
>>
>> (defn producer []
>> (if (dosync (if (not @consuming)
>> (alter data conj 1)))
>> (recur)))
>>
> After rereadi
> thanks a lot. Your code looks much better than mine. But there is one
> part that I don't understand:
>
> (defn producer []
> (if (dosync (if (not @consuming)
>(alter data conj 1)))
>(recur)))
>
>
After rereading the docs several times It seems that I begin to
understand h
Hi, I gave it a try to find a solution to your problem. I ended up
using a single atom to hold the produced data and as means to detect
that consuming started (by swapping in a fn wrapping the produced
value). Don't know wether this fits your problem better than the one
already posted.
(def data
Hi,
thanks a lot. Your code looks much better than mine. But there is one
part that I don't understand:
(defn producer []
(if (dosync (if (not @consuming)
(alter data conj 1)))
(recur)))
How can I be sure that no more data is added to data after @consuming
was set to
I can't claim this is better, but it is shorter - I simply removed
what seemed like some unnecessary syntax:
(def data (ref ()))
(def consuming (ref false))
(defn producer []
(if (dosync (if (not @consuming)
(alter data conj 1)))
(recur)))
(defn consumer []
(dosync (ref-
This is some sort of repost from yesterday. But I hope that this one
describes my problem more precisely.
I have n threads that produce something. At some point in time a
consumer starts and if the consumer starts, no more data should be
produced. Right now I can only come up with the foll
29 matches
Mail list logo