Skip to content

Instantly share code, notes, and snippets.

@ordnungswidrig
Created October 17, 2013 08:21
Show Gist options
  • Save ordnungswidrig/7021114 to your computer and use it in GitHub Desktop.
Save ordnungswidrig/7021114 to your computer and use it in GitHub Desktop.
Avoid the if-let in liberator's exists?
(defn into-context [key value]
(when value
{ key value }))
(ANY "/choice" []
(resource :available-media-types ["text/html"]
:exists? (fn [ctx]
(into-context :choice
(get {"1" "stone" "2" "paper" "3" "scissors"}
(get-in ctx [:request :params "choice"]))))
:handle-ok (fn [ctx]
(format "<html>Your choice: &quot;%s&quot;."
(get ctx :choice)))
:handle-not-found (fn [ctx]
(format "<html>There is no value for the option &quot;%s&quot;"
(get ctx :choice "")))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment