Skip to content

Instantly share code, notes, and snippets.

@bfabry
Last active April 21, 2016 19:01
Show Gist options
  • Save bfabry/dcc2fbb6c21d31718b173026d6bd51c1 to your computer and use it in GitHub Desktop.
Save bfabry/dcc2fbb6c21d31718b173026d6bd51c1 to your computer and use it in GitHub Desktop.
How to do stuff in specter
(def MAP-VALS (sp/comp-paths sp/ALL sp/LAST))
; increment the values for a list of keys
(sp/transform [(apply sp/multi-path [:foo])] inc {:foo 1 :bar 2}) => {:foo 2 :bar 2}
;; or
(sp/transform [(sp/submap [:foo]) MAP-VALS] inc {:foo 1 :bar 2})
;; play with submaps
(sp/select [(submap [:foo :baz])] {:foo 1 :bar 2})
=> [{:foo 1}]
(sp/setval [(submap [:bar])] {:barry 1} {:foo 1 :bar 2})
=> {:foo 1, :barry 1}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment