使幽灵返回所选路径(的一部分)

时间:2018-06-21 01:17:38

标签: clojure specter

在以下结构中,我知道如何迭代:x的所有子项的:whatever值:

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

我想要得到的是类似于以下内容,其中包含通配符map密钥。

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

如何用幽灵来做到这一点?

1 个答案:

答案 0 :(得分:2)

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