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 <https://github.com/nathanmarz/specter>. It's for exactly this use-case and really nice, despite the somewhat funky syntax.
(ns foo.core (:require [com.rpl.specter :as sp])) (def m {:qs [{:nums [3 1 2]} {:nums [7 4]}]}) (sp/transform [:qs sp/ALL :nums sp/ALL] inc m) ;;=> {:qs [{:nums [4 2 3]} {:nums [8 5]}]} On Tuesday, October 10, 2017 at 11:18:56 AM UTC-3, 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 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.