Details
-
Type:
Defect
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Duplicate
-
Affects Version/s: Release 1.4
-
Fix Version/s: None
-
Component/s: None
-
Labels:None
Description
Using update-in with an empty keys vector produces unexpected results:
(update-in {:a 10 :b 20} [] dissoc :a)
⇒ {nil nil, :a 10, :b 20}
(update-in {:a 10 :b 20} [] assoc :c 99)
⇒ {nil {:c 99}, :a 10, :b 20}
The empty keys vector occurs in scenarios where you search on nested maps and later want to update the nested map structure at found paths.
A well-defined behavior is to check the case when the keys vector is empty and then apply only the given function on the given map: (apply f m args)
I think passing in an empty vector should rather be considered an error, since the doc specifies that `ks should be a sequence of keys`.
The same wrong (in my opinion) behaviour is shown by assoc-in