Skip to content

Instantly share code, notes, and snippets.

@denistakeda
Last active December 5, 2018 04:36
Show Gist options
  • Select an option

  • Save denistakeda/264ab3e748394a1d5b7ab4e777126006 to your computer and use it in GitHub Desktop.

Select an option

Save denistakeda/264ab3e748394a1d5b7ab4e777126006 to your computer and use it in GitHub Desktop.
(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