Last active
August 29, 2015 14:07
-
-
Save shaunr0b/b36e135e40034153b34b to your computer and use it in GitHub Desktop.
use cond-> to conditionally add keys to a map
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
;; 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