Fork me on GitHub
#specter
<
2017-03-20
>
mars0i00:03:30

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:

mars0i00:03:05

(select (recursive-path [] p
           (if-path map?
             [ALL (collect-one FIRST) LAST p]
             STAY))
        {: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]]]

mars0i00:03:29

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.

nathanmarz02:03:22

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

nathanmarz02:03:23

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

mars0i03:03:05

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

spieden22:03:33

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)