Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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 ))
(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 ...}
{:tag :cat
:cute? ...
:legs ... }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment