Search code examples
clojurespecter

Make specter return (part of) the selected path


In the following structure, I know how to iterate over the :x values of all children of :whatever:

=> (specter/select
       [:whatever specter/MAP-VALS :x]
       {:whatever {:a {:x 1} :b {:x 2}}})
[1 2]

What I'd like to get though is something like the following, that contains the wild-carded map key.

[[:a 1] [:b 2]]

How can this be done with specter?


Solution

  • (select
            [:whatever ALL (collect-one FIRST) LAST :x]
            {:whatever {:a {:x 1}
                        :b {:x 2}
                        :c {:x 55}}})
    => [[:a 1] [:b 2] [:c 55]]