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 manipulating cells.

In addition, think about ways to flatten the structure. It's a little hard
to figure out what you're trying to do here, but in general try to keep
data one or two layers deep, not only is it easier to manipulate, but it's
also easier to reason about. Once you get 3-4 layers deep in hashmaps, it
gets a bit messy, regardless of the tools you're using.



On Tue, Oct 10, 2017 at 2:18 PM, Rob Nikander <rob.nikan...@gmail.com>
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 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 course you can't write that.  The following code works, but I don't
> like reading it:
>
>     (update m :qs
>         (fn [qs]
>           (mapv
>             (fn [q]
>               (update q :nums #(mapv inc %)))
>             qs)))
>     => {:qs [{:nums [4 2 3]} {:nums [8 5]}]}
>
> Is there an idiomatic way to do this, that looks more like the shorter
> `update-in` idea?
>
> Rob
>
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
“One of the main causes of the fall of the Roman Empire was that–lacking
zero–they had no way to indicate successful termination of their C
programs.”
(Robert Firth)

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to