Last Updated: February 25, 2016
· runexec

Collections and (get)

Clojure collection types don't always behave the same when trying retrieve values between vectors, maps, sets, and structs. This post will look at the differences between the collections and (get).

Value by index
;; Vector user> (def vector-example [:a 1 :b 2]) #'user/vector-example user> (get vector-example 0) :a ;; Hash-Map user> (def map-example (hash-map :a 1 :b 2)) #'user/map-example user> (get map-example 0) nil ;; Set user> (def set-example '(:a 1 :b 2)) #'user/set-example user> (get set-example 0) nil ;; Struct user> (defstruct example :a :b) #'user/example user> (def struct-example (struct example 1 2)) #'user/struct-example user> (get struct-example 0) nil

Value by Key
user> (get vector-example :a) nil user> (get map-example :a) 1 user> (get set-example :a) nil user> (get struct-example :a) 1 user>

Say Thanks
Awesome Job

203f1d44 f7a9 11e7 94d9 1524ba087ecb
Front End Web Developer
Bristol, United Kingdom
Full Time