;; to get an index of the element of a vector, use .indexOf user=> (def v ["one" "two" "three" "two"]) #'user/v user=> (.indexOf v "two") 1 user=> (.indexOf v "foo") -1
;; 'get' is not the only option
user=> (def my-map {:a 1 :b 2 :c 3})
;; maps act like functions
user=> (my-map :a)
1
;; even keys act like functions
user=> (:b my-map)
2
(defn get
"Returns the value mapped to key, not-found or nil if key not present."
{:inline (fn [m k & nf] `(. clojure.lang.RT (get ~m ~k ~@nf)))
:inline-arities #{2 3}
:added "1.0"}
([map key]
(. clojure.lang.RT (get map key)))
([map key not-found]
(. clojure.lang.RT (get map key not-found))))
Comments top
No comments for get. Log in to add a comment.