Skip to content

Instantly share code, notes, and snippets.

(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})
interface Animal {
fun encounter(other: Animal): Decision
}
enum class Decision { RUN_AWAY, EAT, FIGHT, MATE }
class Lion : Animal {
override fun encounter(other: Animal): Decision {
return when (other) {
is Lion -> Decision.FIGHT