Skip to content

Instantly share code, notes, and snippets.

@dmt
Created July 21, 2011 09:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmt/1096875 to your computer and use it in GitHub Desktop.
Save dmt/1096875 to your computer and use it in GitHub Desktop.
multi-method collection type
(defmulti col-type class)
(defmethod col-type clojure.lang.PersistentList [_] :list)
(defmethod col-type clojure.lang.PersistentArrayMap [_] :map)
(defmethod col-type clojure.lang.PersistentVector [_] :vector)
(defmethod col-type clojure.lang.PersistentHashSet [_] :set)
(defmethod col-type :default [col] (if (seq? col) :seq :oops))
(col-type [])
-> :vector
(col-type {})
-> :map
(col-type #{})
-> :set
(col-type '())
-> :seq
(col-type '(1))
-> :list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment