Skip to content

Instantly share code, notes, and snippets.

@jebberjeb
Created October 29, 2013 03:42
Show Gist options
  • Save jebberjeb/7208877 to your computer and use it in GitHub Desktop.
Save jebberjeb/7208877 to your computer and use it in GitHub Desktop.
(ns test-app.core)
(defprotocol Fooable
(foo [this f])
(bar [this b]))
(deftype FooPrinter []
Fooable
(foo [this f] (println "foo: " f))
(bar [this b] (println "bar: " b)))
(foo (FooPrinter.) 3)
(extend java.lang.String
Fooable
{:foo (fn [this f] (str this " foo: " f))
:bar (fn [this b] (str this " bar: " b))})
(println (foo "a string" 3))
(extend clojure.lang.PersistentArrayMap
Fooable
{:foo (fn [this f] (assoc this :foo f))
:bar (fn [this b] (assoc this :bar b))})
(println (foo {:bar "bar" :baz "baz"} "foozle"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment