Skip to content

Instantly share code, notes, and snippets.

@bnyeggen
Created September 21, 2012 15:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bnyeggen/3762181 to your computer and use it in GitHub Desktop.
Save bnyeggen/3762181 to your computer and use it in GitHub Desktop.
Functions can implement protocols too
(defprotocol TwoPersonFn
(operate [this a b]))
(defn shorter? [a b])
(defn marry! [a b])
(defn same-age? [a b])
(extend-type (class shorter?) TwoPersonFn
(operate [this a b] (this a b)))
(extend-type (class marry!) TwoPersonFn
(operate [this a b] (this a b)))
(extend-type (class same-age?) TwoPersonFn
(operate [this a b] (this a b)))
(satisfies? TwoPersonFn shorter?) ; => true
(satisfies? TwoPersonFn marry!) ; => true
(satisfies? TwoPersonFn same-age?) ; => true
(operate shorter? {:height 1} {:height 2}) ;or whatever
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment