Welcome! Please see the About page for a little more info on how this works.

0 votes
in Clojure by
It would be nice if {{assoc-in}} supported multiple key(s)-to-value pairs (and threw an error when there were an even number of arguments, just like {{assoc}}):

user=> (assoc-in {} [:a :b] 1 [:c :d] 2)
{:a {:b 1}, :c {:d 2}}
user=> (assoc-in {} [:a :b] 1 [:c :d])
IllegalArgumentException assoc-in expects even number of arguments after map/vector, found odd number

*Patch:* clj-1771.patch

*Prescreened by:* Alex Miller

5 Answers

0 votes

Comment made by: alex+import

Simple patch attached. I did not find any existing tests for assoc-in but I could add them if wanted.

0 votes

Comment made by: viebel

for the sake of symmetry with assoc I'd love to see this ticket fixed

0 votes

Comment made by: alexmiller

Do you need the "if kvs" check?

Should have tests.

0 votes

Comment made by: mjg123

Sorry for the delay - I don't get notifications from this JIRA for some reason.

The patch now includes tests.

Both if checks are necessary as we have 3 possible outcomes there:
1/ No more kvs (we are finished)
2/ More kvs (we need to recur)
3/ A sequence of keys but no value (throw IAE)

0 votes
Reference: https://clojure.atlassian.net/browse/CLJ-1771 (reported by glittershark)