X Tutup
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/clj/clojure/set.clj
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,10 @@
[map kmap]
(reduce
(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))
m))
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"
Expand Down
5 changes: 3 additions & 2 deletions test/clojure/test_clojure/clojure_set.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
X Tutup