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
| (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}) |
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
| 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 |