specter

Latest version: 1.1.3
nathanmarz 2018-06-07T01:07:29.000054Z

@sophiago it's a lot easier if your maps have more information about what they represent

nathanmarz 2018-06-07T01:07:50.000220Z

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)

sophiago 2018-06-07T01:10:22.000021Z

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"}]})

nathanmarz 2018-06-07T01:15:27.000065Z

this is a cleaner way to write that:

(setval
  [MAP-NODES
   ALL
   (not-selected? FIRST (pred= :locals))
   LAST
   (complement coll?)]
  NONE
  data)

nathanmarz 2018-06-07T01:16:18.000130Z

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)

sophiago 2018-06-07T01:17:45.000209Z

Nice. I think this might be what I'm looking for

sophiago 2018-06-07T01:23:14.000065Z

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

sophiago 2018-06-07T01:25:31.000175Z

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.