Created
October 17, 2013 08:21
-
-
Save ordnungswidrig/7021114 to your computer and use it in GitHub Desktop.
Avoid the if-let in liberator's exists?
This file contains hidden or 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
(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: "%s"." | |
(get ctx :choice))) | |
:handle-not-found (fn [ctx] | |
(format "<html>There is no value for the option "%s"" | |
(get ctx :choice ""))))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment