Fork me on GitHub
#specter
<
2018-02-06
>
jamescroft16:02:39

Hi, I have a nested data structure like in the snippet above. I can select all the nodes of a specified type, but I’m having trouble updating them. I want the index of the node I am updating within the transform function. Any pointers on how to do this? Thanks

nathanmarz16:02:53

@jamescroft you can do that with subselect and a slightly modified NODES

nathanmarz16:02:55

(def NODES (recursive-path [] p (stay-then-continue (must :nodes) ALL p)))
(transform [(subselect NODES #(= "a" (:type %)) :index) (view count)] range data)

jamescroft16:02:36

@nathanmarz great thanks! I wouldn’t have got there on my own!

nathanmarz16:02:24

I highly recommend skimming through https://github.com/nathanmarz/specter/wiki/List-of-Navigators to learn what's available