Skip to content

Instantly share code, notes, and snippets.

@geoffeg
Last active December 22, 2015 21:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save geoffeg/6531708 to your computer and use it in GitHub Desktop.
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.
(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