@sophiago it's a lot easier if your maps have more information about what they represent
this would be a way to do it, though it's not very efficient:
(def data {:baz "qux", :env [{:locals "foo" :k "v"} {:locals "bar"} {:baz "qux"}]})
(def MAP-NODES
(recursive-path [] p
(cond-path map? (stay-then-continue MAP-VALS p)
coll? [ALL p]
)))
(transform
[MAP-NODES
(not-selected?
MAP-VALS
MAP-NODES
(must :locals))]
#(select-keys % [:locals])
data)
Unfortunately, I don't have control over data representation in this case. But I think we're converging on something similar. I'm trying something like this: (setval [MAP-NODES #(and (not= :locals (first %)) (not (coll? (second %))))] NONE {:baz "qux", :env [{:locals "foo"} {:locals "bar"} {:baz "qux"}]})
this is a cleaner way to write that:
(setval
[MAP-NODES
ALL
(not-selected? FIRST (pred= :locals))
LAST
(complement coll?)]
NONE
data)
if you want to get rid of the empty map you can do this:
(def data {:baz "qux", :env [{:locals "foo" :k "v"} {:locals "bar"} {:baz "qux"}]})
(def MAP-NODES
(recursive-path [] p
(cond-path map? (stay-then-continue MAP-VALS p)
coll? [(compact ALL p)]
)))
(setval
[MAP-NODES
ALL
(not-selected? FIRST (pred= :locals))
LAST
(complement coll?)]
NONE
data)
Nice. I think this might be what I'm looking for
Okay, yeah I think that's good enough I can follow it from here. compact
is being called on a keyword at some point in the traversal of a full ast, but I probably want to clean up the results further. Thanks yet again, @nathanmarz
I should probably think about contributing to your docs if you think this is a common enough use case. I would think Specter is ideal for working with tools.analyzer
and in fact there was one Jira ticket for the latter related to Ridley.