简体   繁体   中英

clojure prewalk with select-keys

(clojure.walk/prewalk #(if (map? %)
                           (select-keys  % [:c])
                            %)
                      {:a 1 :b [{:c 3} {:d 4}] :c 5})
=>{:c 5}

why does this only find {:c 5} and not also {:c 3} ? I'm trying to write something that will pull out all key/value pairs that exist for any form and at any level for the key I specify.

When it your function is called with

{:c 5, :b [{:c 3} {:d 4}], :a 1}

...it returns:

{:c 5}

...thus discarding all other keys, including the :b branch, which is thus not traversed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM