Fork me on GitHub

Follow up question about generating paths of keys from embedded maps. My leaf values are sequences of numbers. If I use the first solution you gave, and don't strip out the values using butlast, I almost get what I want:


(select (recursive-path [] p
           (if-path map?
             [ALL (collect-one FIRST) LAST p]
        {:a1 {:b1 [1 2 3]
              :b2 [3 4 5]}
         :a2 {:b2 [6 7 8]}})
;=> [[:a1 :b1 [1 2 3]] [:a1 :b2 [3 4 5]] [:a2 :b2 [6 7 8]]]


What I want is [[:a1 :b1 1 2 3] [:a1 :b2 3 4 5] [:a2 :b2 6 7 8]]. I've been trying to figure out how to do this in specter. Of course it's easy to fix in core Clojure afterwards. If I replace STAY with ALL, I get a separate path vector for each of the numbers in the leaf vectors. Other things I've tried either produce one of these two results, or error. Thanks again for any help.


@mars0i for that it's best to just fix it after the selection, with regular clojure or a transform call


it's possible to do it in one path with specter's zipper integration, but it won't be particularly elegant


OK, thanks very much. Yeah, I'd rather avoid zippers if I can.


thought i’d share a satisfying solution i was just able to rattle off for extracting some information using specter (spr/select [:Resources spr/ALL (spr/collect spr/FIRST) spr/LAST :Properties :ContainerDefinitions spr/ALL :Environment spr/ALL (spr/selected? :Name #(= % "REFERENCE_DATASET")) :Value] t) (i’m on an old version still)