Skip to content

Instantly share code, notes, and snippets.

@bouzuya
Last active December 15, 2015 07:09
Show Gist options
  • Select an option

  • Save bouzuya/5221517 to your computer and use it in GitHub Desktop.

Select an option

Save bouzuya/5221517 to your computer and use it in GitHub Desktop.
(reduce (fn [m [k v]] (assoc m k v)) {} (doto (java.util.HashMap.) (.put "a" 1) (.put "b" 2)))
; => {"a" 1, "b" 2}
(reduce-kv (fn [m k v] (assoc m k v)) {} (doto (java.util.HashMap.) (.put "a" 1) (.put "b" 2)))
; #<IllegalArgumentException java.lang.IllegalArgumentException: No implementation of method: :kv-reduce of protocol: #'clojure.core.protocols/IKVReduce found for class: java.util.HashMap>
(into {} (doto (java.util.HashMap.) (.put "a" 1) (.put "b" 2)))
; => {"b" 2, "a" 1}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment