hi folks, wondering if someone can help me understand why the following are not equivalent
@jeremyraines uploaded a file: https://clojurians.slack.com/files/U050R08D8/FB3TRKTAT/-.clj
where the contents of the atom foo
are exactly the vec returned from the first expression
@jeremyraines filterer
takes in a subpath and keeps elements for which that path navigates to at least one value
:bar
always navigates
you can do (sp/select [sp/ATOM (sp/filterer (pred :bar)) sp/ALL] foo)
ah, got it. Thank you!
@nathanmarz I just started playing with specter, itโs been on my list for a while. Iโm mad at myself for not using this work of art sooner! Just wanted to say thanks for making this and youโre doing Godโs work! ๐
@currentoor thanks :)
dealing the salesforce API just got a whole lot easier (and more fun)!
I modified the map-key-walker
example from the wiki page on recursive navigators so that it will look inside vectors as well as maps, but ideally i'd like to navigate to the inverse so I can delete all other key-value pairs and leave the ones selected with the structure they were nested in.
select
works fine
Same issue if I try using transform
with select-keys
๐
@sophiago you're trying to do too much in those paths
don't navigate to both all the recursive maps and to a specific key in the same path
have one path that navigates to all the maps and then navigate to the key from there
(def data {:baz "qux", :locals [{:locals "foo"} {:locals "bar"} {:baz "qux"}]})
(def MAP-NODES
(recursive-path [] p
(cond-path map? (continue-then-stay MAP-VALS p)
coll? [ALL p]
)))
(transform MAP-NODES #(select-keys % [:locals]) data)
not sure what you mean by "inverse"
you mean get rid of all ":locals" keys in all maps?
No, I meant select for every k-v pair where the key is not the one specified. I figured using a navigator like that with (setval [..] NONE ..)
would be the easiest way to preserve structure.
that's just [ALL (selected? FIRST #(not= % k)) LAST]
Ah. Okay, thanks. I don't think that's even necessary now, though. I was fairly close to your solution in some of the navigators I tried, but not quite ๐
I'm still having trouble with your version of MAP-NODES
and a full ast from tools.analyzer.jvm
though
Right, it still doesn't search bottom-up meaning it will prune branches that still contain the keys I'm looking for, e.g. (def data {:baz "qux", :env [{:locals "foo"} {:locals "bar"} {:baz "qux"}]})
returns an empty map.
So that works as well as my second example above, but still fails on the same case
I'm realizing just how difficult it is to do breadth-first search in Clojure ๐
I mean, I can return the elements of a tree in breadth-first order but can't figure out how to transform it in that order.
This is what I'm going for with a lengthy example you'd want to pretty-print: https://gist.github.com/Sophia-Gold/d48be3ec125a453de7cec2033a465ef8
@sophiago shared a file: https://clojurians.slack.com/files/U2TCUSM2R/FB4508EFR/walk-ast.clj
But really, the tiny examples in my second paste above cover the problem. In case it wasn't clear, it was working on the first structure and failing on the second.