Created
February 11, 2012 11:15
-
-
Save j1n3l0/1798837 to your computer and use it in GitHub Desktop.
Clojure Protocols #clojure
This file contains 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
(defprotocol Foo | |
"Does Foolike things" | |
(bar [a b] "does stuff with a & b") | |
(baz [a] "does stuff with a")) | |
(extend-protocol Foo | |
nil | |
(bar [_ _] nil) | |
(baz [_] nil) | |
String | |
(bar [a b] {:a a :b b})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When you extend a protocol to a given type you only need to implement the methods that make sense for you. You'll get exceptions if you try calling a function you haven't implemented. Sweet :)