specter

Latest version: 1.1.3
jeremyraines 2018-06-06T17:27:37.000034Z

hi folks, wondering if someone can help me understand why the following are not equivalent

jeremyraines 2018-06-06T17:28:05.000565Z

@jeremyraines uploaded a file: https://clojurians.slack.com/files/U050R08D8/FB3TRKTAT/-.clj

jeremyraines 2018-06-06T17:28:53.000059Z

where the contents of the atom foo are exactly the vec returned from the first expression

nathanmarz 2018-06-06T17:31:10.000710Z

@jeremyraines filterer takes in a subpath and keeps elements for which that path navigates to at least one value

nathanmarz 2018-06-06T17:31:17.000481Z

:bar always navigates

nathanmarz 2018-06-06T17:31:37.000548Z

you can do (sp/select [sp/ATOM (sp/filterer (pred :bar)) sp/ALL] foo)

jeremyraines 2018-06-06T17:32:01.000332Z

ah, got it. Thank you!

currentoor 2018-06-06T17:55:13.000347Z

@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! ๐Ÿ˜„

nathanmarz 2018-06-06T17:58:04.000333Z

@currentoor thanks :)

currentoor 2018-06-06T17:58:33.000043Z

dealing the salesforce API just got a whole lot easier (and more fun)!

sophiago 2018-06-06T21:29:19.000134Z

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.

sophiago 2018-06-06T21:30:05.000239Z

select works fine

sophiago 2018-06-06T21:56:21.000265Z

Same issue if I try using transform with select-keys ๐Ÿ˜•

nathanmarz 2018-06-06T23:18:24.000153Z

@sophiago you're trying to do too much in those paths

nathanmarz 2018-06-06T23:19:01.000105Z

don't navigate to both all the recursive maps and to a specific key in the same path

nathanmarz 2018-06-06T23:19:14.000014Z

have one path that navigates to all the maps and then navigate to the key from there

nathanmarz 2018-06-06T23:19:35.000031Z

(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)

nathanmarz 2018-06-06T23:19:45.000017Z

not sure what you mean by "inverse"

nathanmarz 2018-06-06T23:20:10.000166Z

you mean get rid of all ":locals" keys in all maps?

sophiago 2018-06-06T23:22:42.000204Z

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.

nathanmarz 2018-06-06T23:23:24.000345Z

that's just [ALL (selected? FIRST #(not= % k)) LAST]

sophiago 2018-06-06T23:24:36.000243Z

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 ๐Ÿ˜›

sophiago 2018-06-06T23:27:16.000178Z

I'm still having trouble with your version of MAP-NODES and a full ast from tools.analyzer.jvm though

sophiago 2018-06-06T23:29:40.000048Z

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.

sophiago 2018-06-06T23:30:45.000018Z

So that works as well as my second example above, but still fails on the same case

sophiago 2018-06-06T23:31:52.000302Z

I'm realizing just how difficult it is to do breadth-first search in Clojure ๐Ÿ˜•

sophiago 2018-06-06T23:33:06.000137Z

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.

sophiago 2018-06-06T23:45:55.000309Z

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 2018-06-06T23:45:57.000110Z

@sophiago shared a file: https://clojurians.slack.com/files/U2TCUSM2R/FB4508EFR/walk-ast.clj

sophiago 2018-06-06T23:47:03.000102Z

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.