Skip to content

Instantly share code, notes, and snippets.

@ihercowitz
Created August 12, 2013 12:11
Show Gist options
  • Select an option

  • Save ihercowitz/5397fc60772f04d1d8ee to your computer and use it in GitHub Desktop.

Select an option

Save ihercowitz/5397fc60772f04d1d8ee to your computer and use it in GitHub Desktop.
A very simple polymorphic method in clojure
(defprotocol Hello (say [x]))
(extend-protocol Hello
String (say [x] (str "Hello String " x))
Long (say [x] (str "Hello Number " x)))
;usage
(say "World") ;expected: "Hello String World"
(say 42) ;expected: "Hello Number 42"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment