specter

Latest version: 1.1.3
phreed 2018-02-05T17:55:54.000829Z

Which macro provides the ability to select nodes from a tree whose subpath matches a pattern? e.g. Given (def foo {"a1" {:z :c1, :d "e1"} "a2" {:z :c2, :d "e2"}}) (select [ALL (magic [VAL :z :c1])] foo) > {"a1" {:z :c1, :d "e1"} } What is the magic macro? Should I be using transform instead of select?

nathanmarz 2018-02-05T18:09:19.000150Z

@phreed you're looking to filter submaps that don't contain a key-value pair [:z :c1]?

phreed 2018-02-05T18:13:06.000026Z

@nathanmarz yes, I think that is right.

nathanmarz 2018-02-05T18:13:20.000416Z

the basic pattern for that is (setval <path> NONE data)

nathanmarz 2018-02-05T18:13:26.000319Z

in this case (setval [MAP-VALS (not-selected? :z (pred= :c1))] NONE foo)

phreed 2018-02-05T18:13:50.000285Z

yes, pruning the tree with setval does the trick.

phreed 2018-02-05T18:50:52.000675Z

I am looking at the documentation for not-selected? it appears to take only one argument, a path. What is going on here (not-selected? :z (pred= :c1)) that looks like two arguments. Is it equivalent to (not-selected? [:z (pred= :c1)]) ?

nathanmarz 2018-02-05T18:58:14.000500Z

@phreed yes, those are equivalent

nathanmarz 2018-02-05T18:58:38.000367Z

similarly the path [:a :b :c] is the same as [[:a] [[:b]] :c]

nathanmarz 2018-02-05T18:59:38.000029Z

a path is just a composition of navigators

nathanmarz 2018-02-05T19:00:01.000566Z

a vector in a path is interpreted as a path