clojure - 让幽灵返回所选路径(部分)

标签 clojure specter

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

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

我想要得到的是类似下面的内容,其中包含通配符的 map 键。

[[:a 1] [:b 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]]

关于clojure - 让幽灵返回所选路径(部分),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50959074/

相关文章:

clojure - 可以接受原语和元数据的最简单的 Clojure 对象?

clojure - 在 Clojure 中使用 Spectre 删除嵌套值

Clojure - 使用spectre转换嵌套数据结构,用多个节点替换一个节点

clojure - 如何在 ClojureScript 中使用 Spectre?

Clojure 幽灵 : how to find map keys that have specific value?

node.js - 使用 Aleph/Lamina 异步访问 MongoDB

clojure - 是否期望 identity 返回与其参数不同的东西?

clojure - "do additional stuff when ..."的 Clojure 方式是什么

clojure - 安装 Leiningen 以与 Clojure 一起使用