function/macro | since v0.0-927 | clojure.core/hash-map | Edit |
(hash-map & keyvals)
Returns a new hash map with supplied mappings.
keyvals
must be an even number of forms.
keyval => key val Returns a new hash map with supplied mappings.
(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))))
(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))))