Fork me on GitHub
#specter
<
2017-08-21
>
michaelwfogleman12:08:55

pred= and friends are great!

michaelwfogleman12:08:26

@nathanmarz Is it possible to contribute to the Specter wiki?

michaelwfogleman12:08:31

When you first mentioned recursive-path, I noticed it wasn't documented (in the Macros section?). I dug up the mention in Changes.MD that had an example. I cloned the wiki and made a change locally but would like to contribute it

nathanmarz12:08:30

@michaelwfogleman yea, I wish github had a way to make pull requests for project wikis

nathanmarz12:08:58

maybe I can make the specter wiki its own project and keep it in sync myself

michaelwfogleman12:08:56

Happy to tweak the documentation if it's not quite right. 🙂

nathanmarz12:08:18

awesome, merged

nathanmarz12:08:32

should probably add example of transform and an example of a parameterized recursive-path

nathanmarz12:08:41

can open issues on specter-wiki repository for anything you find that's lacking

nathanmarz12:08:49

(which is probably a lot of things)

twillis12:08:23

hello, just discovered specter yesterday and I thought it might help me transforming honeysql queries. for example given...

{:select (:*), :from (:table), :where [:or [:and [:= :a 1] [:b 1]] [:and [:= :c 1] [:= :d 1]]]}
example: if i need to add [:= :active true] to each clause. having trouble specifying the path past [:where ALL] , i guess it's a problem with the sequences having a keyword as the first element.

nathanmarz14:08:52

@twillis do you want to add that clause to the top-level of :where (e.g. [:and [:= :active true] [:or ...]]) or within each :and clause?

nathanmarz14:08:18

if the latter you'll probably need a recursive path since :and and :or can nest arbitrarily

twillis14:08:29

well in the above example I was thinking of adding to each clause but it was just an arbitrary example. but I think the issue i'm having is that I dont know how to get to things in a vector where the first item is a keyword.

nathanmarz14:08:34

you can use this to navigate to each node in tree:

(def TreeNodes
    (recursive-path [] p
     (if-path sequential?
       (continue-then-stay ALL p)
       STAY
       )))

nathanmarz14:08:52

then something like this for your transform:

(setval [:where TreeNodes vector? (selected? FIRST (pred= :and)) AFTER-ELEM] [:= :active true] data)

twillis14:08:27

ok thanks for your help @nathanmarz

urbank17:08:18

Hm... where does pred= come from? Is it just a user defined function?

urbank18:08:13

Oh, it's a specter function. Didn't notice that none of the functions were namespaced in the samples

nathanmarz18:08:13

it's just a convenience, same as #(= % some-val)

urbank18:08:54

Yeah, figured. Just thought it was a part of clojure core or something