Skip to content

Instantly share code, notes, and snippets.

@Vadym-Lopatka
Last active October 26, 2024 14:22
Show Gist options
  • Select an option

  • Save Vadym-Lopatka/88744eff093514b67b9e04fbb18bf01e to your computer and use it in GitHub Desktop.

Select an option

Save Vadym-Lopatka/88744eff093514b67b9e04fbb18bf01e to your computer and use it in GitHub Desktop.
(defmulti encounter (fn [x y] [(:Species x) (:Species y)]))
(defmethod encounter [:Bunny :Lion] [b l] :run-away)
(defmethod encounter [:Lion :Bunny] [l b] :eat)
(defmethod encounter [:Lion :Lion] [l1 l2] :fight)
(defmethod encounter [:Bunny :Bunny] [b1 b2] :mate)
(def b1 {:Species :Bunny :other :stuff})
(def b2 {:Species :Bunny :other :stuff})
(def l1 {:Species :Lion :other :stuff})
(def l2 {:Species :Lion :other :stuff})
(encounter b1 b2) ;: :mate
(encounter b1 l1) ;: :run-away
(encounter l1 b1) ;: :eat
(encounter l1 l2) ;: :fight
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment