Is there a jQuery type function to solve the problem of walking through nested maps?
for example, if i have a configuration that looks like this:
(def fig
{:config
{:example
{:a "a"
:b "b"
:c "c"}
:more
{:a "a"
:b "b"
:c "c"}}})
I still haven’t figured out a great way to manipulate nested persistent data structures with assoc and dissoc. However, if there was a jquery style way to manipulate maps, then I can write code like this:
(-> fig
($ [:config :example :a] #(str % "a"))
($ [:config :b] #(str % "b")))
Giving this output:
{:config
{:example
{:a "aa"
:b "bb"
:c "c"}
:more
{:a "a"
:b "bb"
:c "c"}}}
And something like this for selectors:
($ fig [:config :example :a])
;=> "a"
($ fig [:config :b])
;=> {[:config :example :b] "b",
; [:config :more :b] "b"}
So in essence, I’m looking for an implementation of jayq for manipulation of clojure objects instead of html doms.
Thanks in advance!
First of all, you should check out Enlive.
Otherwise: if you want to do what jQuery does (of course very simplified) – as opposed to just calling update-in:
Select:
For call:
it should yield:
Update/replace:
For call:
it should yield:
I didn’t test it thoroughly though.