Skip to content

Instantly share code, notes, and snippets.

@mecdemort
Created March 31, 2011 21:20
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 mecdemort/897285 to your computer and use it in GitHub Desktop.
Save mecdemort/897285 to your computer and use it in GitHub Desktop.
If a map contains a key, do something
(cond
(:key1 m) key1
(:key2 m) key2
(:key3 m) key3
:else nokey)
(condp apply [m]
:key1 key1
:key2 key2
:ley3 key3
nokey)
(condp #(%2 %1) m
:key1 key1
:key2 key2
:ley3 key3
nokey)
(or (some (map #(when (%1 m) %2) [:key1 :key2 :key3] [key1 key2 key3]))
nokey)
(condp m nil
:key1 key1
:key2 key2
:key3 key3
nokey)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment