Re: Updating repeated nested structures?

2017-10-10 Thread aleks m s
I agree with someone else that the first thing you should do is see if you can flatten the data in some way. I find that namespaced keywords often help with that. If it doesn't make sense to flatten it, however, I'd use specter . It's for exactly this

Re: Updating repeated nested structures?

2017-10-10 Thread Gary Trakhman
I wrote a terrible terrible function once to help with this while bored in jury duty, called flipartial, in the style of core's 'let's expand/optimize out the most common arities': (defn flipartial "A combo of partial/flip, makes it easier to fake-curry non-data-last functions. In general, only

Re: Updating repeated nested structures?

2017-10-10 Thread hitesh
It's not terse, but it is easier to follow. (defn flip [f x y] (f y x)) (defn update-nums [m f] (update m :qs (fn [x] (flip map x (fn [x] (update-in x [:nums] #(map f %))) ;; (update-nums m

Re: Updating repeated nested structures?

2017-10-10 Thread Rob Nikander
Gah. I changed one name and not another. I meant: (update-in m [:qs * :nums] ...) On Tuesday, October 10, 2017 at 10:18:56 AM UTC-4, Rob Nikander wrote: > > Hi, > > Say I have a map like this: > > (def m {:qs [{:nums [3 1 2]} {:nums [7 4]}]}) > > I want to transform each number with a

Re: Updating repeated nested structures?

2017-10-10 Thread Timothy Baldridge
My answer to most of these questions is often "write it once, stuff it in a function, and forget about it". Really though I often see this as a data-modeling and naming problem. For example, you could go and write a `(update-cells cell-list f & args)` that wraps custom logic for finding and

Updating repeated nested structures?

2017-10-10 Thread Rob Nikander
Hi, Say I have a map like this: (def m {:qs [{:nums [3 1 2]} {:nums [7 4]}]}) I want to transform each number with a function (say, `inc`). I imagine something like this: (update-in m [:qs * :cell-fns] #(map inc %)) ; or (update-in m [:qs * :cell-fns *] inc) But of