Skip to content

Instantly share code, notes, and snippets.

@swannodette
Forked from mecdemort/sequable?.clj
Created May 1, 2011 00:43
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 swannodette/950144 to your computer and use it in GitHub Desktop.
Save swannodette/950144 to your computer and use it in GitHub Desktop.
(ns logic.core)
(defprotocol ISeqable
(seqable? [x]))
(defmacro extend-to-seqable [& xs]
`(extend-protocol ISeqable
~@(mapcat (fn [x] [x `(~'seqable? [~'x] true)]) xs)))
(extend-to-seqable
clojure.lang.ISeq
clojure.lang.Seqable
Iterable
CharSequence
String
java.util.Map
nil)
(comment
;; 300ms
(dotimes [_ 10]
(time
(dotimes [_ 1e8]
(seqable? "foo"))))
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment