Created
February 19, 2014 05:29
-
-
Save txrev319/9086538 to your computer and use it in GitHub Desktop.
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
The following code | |
(defn do-stuff [msg] | |
(hmatch msg | |
[:dog age name] (println "got a dog with age " age " and name " name) | |
[:cat cute? legs] (println "got a cat that is " cute? " cute and has " legs "legs") | |
[other] (println "got an unrecognized animal of type " other )) | |
becomes: | |
(defn do-stuff [msg] | |
(case (tag :msg) | |
:dog (let [{:keys [age name]} msg] ...) | |
:cat (let [{:keys [cute? legs]} msg] ... ) | |
(let [other (:tag msg)] ... ))) | |
so basically, this "pattern matches" on objects of the form: | |
{:tag :dog | |
:age ... | |
:name ...} | |
and | |
{:tag :cat | |
:cute? ... | |
:legs ... } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment