Skip to content

Instantly share code, notes, and snippets.

@shaunr0b
Last active August 29, 2015 14:07
Show Gist options
  • Save shaunr0b/b36e135e40034153b34b to your computer and use it in GitHub Desktop.
Save shaunr0b/b36e135e40034153b34b to your computer and use it in GitHub Desktop.
use cond-> to conditionally add keys to a map
;; Use cond-> to conditionally add keys to a map
;; http://grimoire.arrdem.com/1.6.0/clojure.core/cond-%3E/
(let [a 3
b nil
c false
d "word"]
(cond->
{}
a
(assoc :a a)
b
(assoc :b b)
c
(assoc :c c)
d
(assoc :d d)))
;; => {:d "word", :a 3}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment