Fork me on GitHub
#specter
<
2023-04-14
>
mmer13:04:35

Hi I have a parsed yaml file and I want to select a tree where the first map entry contains a key of value x and content of y.

chromalchemy17:04:15

If your selecting a single node (and the tree is sufficiently nested within that node), you can simply select it like this

(select-one [ALL (selected? map? :key (pred= val))] collection)
If you need to filter out the other attribues of nested nodes: I don’t have a good intuition of the recursive paths, but it can look something like this:
(select 
  (recursive-path [] p
    (if-path my-predicate?
       (continue-then-stay :mykeyword ALL p))) 
  collection)
That only selects the tree of keyword :mykeyword . You would probably l need to modify the continue path. Docs: https://github.com/redplanetlabs/specter/wiki/Using-Specter-Recursively You can check out some interesting implementations in the navigator collection libraries that have been shared. https://clojars.org/search?q=specter