Last active
December 5, 2018 04:36
-
-
Save denistakeda/264ab3e748394a1d5b7ab4e777126006 to your computer and use it in GitHub Desktop.
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
| (ns overweight.core) | |
| (def animals | |
| [{:type :cat | |
| :name "Tom" | |
| :weight 3} | |
| {:type :dog | |
| :breed :boxer | |
| :weight 12} | |
| {:type :cat | |
| :name "Simon" | |
| :weight 120} ;; Большой жирный кот | |
| ]) | |
| (defmulti say | |
| (fn [{:keys [weight type]}] | |
| (if (> weight 100) :big-animal type))) | |
| (defmethod say :big-animal [animal] "Hru hru") | |
| (defmethod say :dog [_] "Wof wof") | |
| (defmethod say :cat [_] "Miau") | |
| (map say animals) ;; -> ("Miau" "Wof wof" "Hru hru") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment