Skip to content

Instantly share code, notes, and snippets.

@nathanmarz
Last active August 29, 2015 14:23
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 nathanmarz/6333a50c67ec9031e5ee to your computer and use it in GitHub Desktop.
Save nathanmarz/6333a50c67ec9031e5ee to your computer and use it in GitHub Desktop.
New if-path selector in Specter
;; For every map, if value for :a is even, increment :b's value. Otherwise, increment all values.
(update [ALL (if-path [:a even?] :b [ALL LAST])]
inc
[{:a 2 :b 3 :c 4}
{:a 1 :b 10 :d 5 :e 6}
{:a 2 :b 0}
{:a -1 :f 100}])
==>
[{:c 4, :b 4, :a 2}
{:e 7, :b 11, :d 6, :a 2}
{:b 1, :a 2}
{:f 101, :a 0}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment