hash-map

function/macrosince v0.0-927 clojure.core/hash-mapEdit
(hash-map & keyvals)

Details:

Returns a new hash map with supplied mappings.

keyvals must be an even number of forms.


See Also:


Source docstring:
keyval => key val
Returns a new hash map with supplied mappings.
Function code @ clojurescript:src/main/cljs/cljs/core.cljs
(defn hash-map
  [& keyvals]
  (loop [in (seq keyvals), out (transient (.-EMPTY PersistentHashMap))]
    (if in
      (let [in' (next in)]
        (if (nil? in')
          (throw (js/Error. (str "No value supplied for key: " (first in))))
          (recur (next in') (assoc! out (first in) (first in')) )))
      (persistent! out))))

Macro code @ clojurescript:src/main/clojure/cljs/core.cljc
(core/defmacro hash-map
  ([] `(.-EMPTY cljs.core/PersistentHashMap))
  ([& kvs]
   (core/let [pairs (map
                      (core/fn [pair]
                        (remove #{::missing} pair))
                      (partition 2 2 (repeat ::missing) kvs))
              ks    (map first pairs)
              vs    (map second (take-while #(= 2 (count %)) pairs))]
     (vary-meta
       `(.fromArrays cljs.core/PersistentHashMap (array ~@ks) (array ~@vs))
       assoc :tag 'cljs.core/PersistentHashMap))))