Last active
September 29, 2015 03:36
-
-
Save lbradstreet/2e84fe962aa4f8fc9485 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def | |
^{:arglists '([map key val] [map key1 val1 key2 val2] [map key val & kvs]) | |
:doc "assoc[iate]. When applied to a map, returns a new map of the | |
same (hashed/sorted) type, that contains the mapping of key(s) to | |
val(s). When applied to a vector, returns a new vector that | |
contains val at index. Note - index must be <= (count vector)." | |
:added "1.0" | |
:static true} | |
assoc | |
(fn ^:static assoc | |
([map key val] (clojure.lang.RT/assoc map key val)) | |
([map key1 val1 key2 val2] (clojure.lang.RT/assoc (clojure.lang.RT/assoc map key1 val1) key2 val2)) | |
([map key1 val2 key2 val2 & kvs] | |
(let [ret (clojure.lang.RT/assoc (clojure.lang.RT/assoc map key1 val1) key2 val2))] | |
(if kvs | |
(if (next kvs) | |
(recur ret (first kvs) (second kvs) (nnext kvs)) | |
(throw (IllegalArgumentException. | |
"assoc expects even number of arguments after map/vector, found odd number"))) | |
ret))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I fixed the order of the assocs between k1/v1, k2,v2. I believe it should assoc k1 first, then k2