Skip to content

Instantly share code, notes, and snippets.

@tafsiri
Created July 26, 2011 03:06
Show Gist options
  • Save tafsiri/1105856 to your computer and use it in GitHub Desktop.
Save tafsiri/1105856 to your computer and use it in GitHub Desktop.
(ns day1.core)
(defn big [str n]
"Returns true if string [str] is longer than [n]
false otherwise"
(> (count str) n))
;usage
(big "hello" 2)
(big "hello" 8)
(defn collection-type [col]
"Returns :list, :map, :vector based on the
type of collection [col]"
(if (list? col) :list
(if (map? col) :map
(if (vector? col) :vector
"None of the above"))))
(defn collection-type-cond [col]
"Returns :list, :map, :vector based on the
type of collection [col]"
(cond
(list? col) :list
(map? col) :map
(vector? col) :vector
:else "None of the above"))
;usage
(collection-type [1,2,3])
(collection-type '(1,2,3))
(collection-type {:one 1, :two 2, :three 3})
(collection-type "huh")
(collection-type-cond [1,2,3])
(collection-type-cond '(1,2,3))
(collection-type-cond {:one 1, :two 2, :three 3})
(collection-type-cond "huh")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment