Skip to content

Instantly share code, notes, and snippets.

@Bost
Last active December 16, 2015 07:39
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 Bost/5400289 to your computer and use it in GitHub Desktop.
Save Bost/5400289 to your computer and use it in GitHub Desktop.
clojure - collections
(defn persistent-hash-map [k v]
"Create PeristentHashMap - performs faster for larger maps"
(hash-map k v))
(type (persistent-hash-map :a 1))
(defn persisten-array-map [k v]
"Create PeristentArrayMap - only suitable for very small maps"
{k v})
(type (persisten-array-map :a 1))
; clojure.lang.PeristentHashMap - performs faster for larger maps
(def y {:a 1})
(type y)
; clojure.lang.Var
(type (def y {:a 1}))
(def y {:a 1})
; clojure.lang.PeristentHashMap - performs faster for larger maps
(type y)
; clojure.lang.PersistentList
(type '(def y {:a 1}))
; clojure.lang.PeristentArrayMap - only suitable for very small maps
(type {:a 1})
; clojure.lang.PersistentHashSet
(type #{1 2})
{} ;hash-map
#{} ;hash-set
() ;list
[] ;vector
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment