Browse files

fixed rename-keys to not delete entries when there is a collision

  • Loading branch information...
1 parent f416abb commit 5be3369e1f67eb2f37a485872de4fe60a352e87a @l0st3d committed May 4, 2012
Showing with 6 additions and 6 deletions.
  1. +3 −4 src/clj/clojure/set.clj
  2. +3 −2 test/clojure/test_clojure/clojure_set.clj
@@ -80,11 +80,10 @@
[map kmap]
(fn [m [old new]]
- (if (and (not= old new)
- (contains? m old))
- (-> m (assoc new (get m old)) (dissoc old))
+ (if (contains? map old)
+ (assoc m new (get map old))
- map kmap))
+ (apply dissoc map (keys kmap)) kmap))
(defn rename
"Returns a rel of the maps in xrel with the keys in kmap renamed to the vals in kmap"
@@ -162,8 +162,9 @@
(deftest test-rename-keys
(are [x y] (= x y)
- (set/rename-keys {:a "one" :b "two"} {:a :z}) {:z "one" :b "two"}
- ))
+ (set/rename-keys {:a "one" :b "two"} {:a :z}) {:z "one" :b "two"}
+ (set/rename-keys {:a "one" :b "two"} {:a :z :c :y}) {:z "one" :b "two"}
+ (set/rename-keys {:a "one" :b "two" :c "three"} {:a :b :b :a}) {:a "two" :b "one" :c "three"}))
(deftest test-index
(are [x y] (= x y)

0 comments on commit 5be3369

Please sign in to comment.