Skip to content

Instantly share code, notes, and snippets.

@andrewvc
Created February 8, 2012 17:18
Show Gist options
  • Save andrewvc/1771297 to your computer and use it in GitHub Desktop.
Save andrewvc/1771297 to your computer and use it in GitHub Desktop.
(defn increment-keys
"Given a map and a list of keys, this will return an identical map with those keys
with those keys incremented.
Keys with a null value will be set to 1."
[src-map & xs]
(into src-map (map #(vector %1 (inc (get src-map %1 0))) xs)))
; Example (increment-keys {:a 2} :a :b) => {:a 3 :b 1}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment