Skip to content

Instantly share code, notes, and snippets.

@j1n3l0
Created February 11, 2012 11:15
Show Gist options
  • Save j1n3l0/1798837 to your computer and use it in GitHub Desktop.
Save j1n3l0/1798837 to your computer and use it in GitHub Desktop.
Clojure Protocols #clojure
(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}))
@j1n3l0
Copy link
Author

j1n3l0 commented Feb 11, 2012

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment