Last active
August 29, 2015 14:23
-
-
Save nathanmarz/6333a50c67ec9031e5ee to your computer and use it in GitHub Desktop.
New if-path selector in Specter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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