Last active
December 22, 2015 21:09
-
-
Save geoffeg/6531708 to your computer and use it in GitHub Desktop.
Find the matching key in qparams and parammap and execute the matching parammap value with the qparam value as the argument.
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
(let [qparams {"cat" "meow"} | |
parammap {"cat" #(println "feline says" %), "dog" #(println "canine says" %)} | |
foundparam (into {} (filter #(contains? parammap (key %)) qparams))] | |
((get parammap (key (first foundparam))) (val (first foundparam)))) | |
;> feline says meow | |
; Cleaner? | |
(let [queryparams {:cat "meow", :cheese "nonsense"} | |
functionmap {:cat #(println "feline says" %), :dog #(println "canine says" %)} | |
selectedkey (first (select-keys functionmap (keys queryparams)))] | |
((val selectedkey) (queryparams (key selectedkey)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment