Skip to content

Instantly share code, notes, and snippets.

@jeff303
Created April 21, 2021 20:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeff303/b3711b720bbdb06b7b77a737b528b0e1 to your computer and use it in GitHub Desktop.
Save jeff303/b3711b720bbdb06b7b77a737b528b0e1 to your computer and use it in GitHub Desktop.
Remove keys with the word "password" from deeply nested maps using Specter
(require '[com.rpl.specter :refer :all])
(def data {:a 1 :b 2 :c {:x 14 :my-password "foo" :y {:foo "bar" :baz-password-value "secret" :z 141}}})
;; from https://github.com/redplanetlabs/specter/wiki/Using-Specter-Recursively#recursively-navigate-to-every-map-in-a-map-of-maps
(def MAP-NODES
(recursive-path [] p
(if-path map?
(continue-then-stay MAP-VALS p))))
(setval [MAP-NODES MAP-KEYS #(->> % name (re-matches #".*password.*"))] NONE data)
=> {:a 1, :b 2, :c {:x 14, :y {:foo "bar", :z 141}}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment