Created
May 1, 2013 20:16
-
-
Save ifesdjeen/5498023 to your computer and use it in GitHub Desktop.
Clojure Multimethods
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 even-odd | |
(fn [i] | |
(if (= 0 (mod i 2)) | |
:even | |
:odd))) | |
(defmethod even-odd :even | |
[i] | |
(println "Even " i)) | |
(defmethod even-odd :odd | |
[i] | |
(println "Odd " i)) | |
(even-odd i) | |
(even-odd 1) | |
;; Odd 1 | |
;; => nil | |
(even-odd 2) | |
;; Even 2 | |
;; => nil | |
(even-odd 3) | |
;; Odd 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment