Hi,
I have this use-case for (update-in) which keeps showing up in my code
which I don't have a solution for and I'm wondering if there isn't a
solution.
How do I _efficiently_ obtain the new value created by an invocation of
(update-in), that is, without having to get the modified value by
Here is one way to do it called update-in+. It returns a vector consisting
of the new udpated value, like update-in does, followed by the original
value (in case you might want to see that for some reason), followed by the
updated value.
(defn update-in+
([m [k ks] f args]
(if ks
I would have written the fn like this, if I was following what you've been
doing:
(def m {:planet {:country {:state {:city {:borough 4})
(let [mm (update-in m [:planet :country :state :city :borough ] (fnil inc
-1))]
(get-in mm [:planet :country :state :city :borough ]))
However, when I
Thanks Andy,
Two comments:
1. Your version does not use a transient/mutable, which is great, but it
does create one vector for each level. I thought that since this would be
wrapped and hidden from external view, a mutable would have been more
appropriate. More generally, I still don't know
On Thu, Apr 26, 2012 at 4:30 PM, blais goo...@furius.ca wrote:
(Generally I find I get too little cultural osmosis when it comes to
practical application of Clojure, so questions like this one come up all
the time while I'm coding. Meetups and books touch on topics I understand
well but
On Thursday, April 26, 2012 4:36:52 PM UTC-4, David Nolen wrote:
On Thu, Apr 26, 2012 at 4:30 PM, blais goo...@furius.ca wrote:
(Generally I find I get too little cultural osmosis when it comes to
practical application of Clojure, so questions like this one come up all
the time while I'm
On Thu, Apr 26, 2012 at 4:52 PM, blais goo...@furius.ca wrote:
I suppose I could elect to move refs for modifiable things towards the
leaves, but that seems to me like going against the grain and may have
implications for concurrency (there are few but some threads running in
parallel in this
On Thursday, April 26, 2012 4:59:31 PM UTC-4, David Nolen wrote:
On Thu, Apr 26, 2012 at 4:52 PM, blais goo...@furius.ca wrote:
I suppose I could elect to move refs for modifiable things towards the
leaves, but that seems to me like going against the grain and may have
implications for
On Thu, Apr 26, 2012 at 5:08 PM, blais goo...@furius.ca wrote:
I receive events from a network. My application calls for storing these
events and doing different things based on the changing status of orders
attached to these events. I need to store them somewhere, I need to track
this state
I think you are too concerned with micro optimizations. get-in is probably
just as efficient as attempting to bubble the state change back up and
certainly simpler to work with. In practice, optimizations like this do not
have a significant impact on the overall performace.
Measure before
10 matches
Mail list logo