Skip to content

Commit

Permalink
* implement IHash for js Symbol
Browse files Browse the repository at this point in the history
* add test cases
  • Loading branch information
swannodette committed Feb 21, 2024
1 parent 4f400cb commit 4defb9e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/main/cljs/cljs/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -1458,6 +1458,11 @@
(-hash [o]
(goog/getUid o)))

(extend-type symbol
IHash
(-hash [o]
(hash (.toString o))))

;;this is primitive because & emits call to array-seq
(defn inc
"Returns a number one greater than num."
Expand Down
8 changes: 8 additions & 0 deletions src/test/cljs/cljs/hashing_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,11 @@
(is (= (hash 0.5) (hash 0.5)))
(is (= (hash -0.32553251) (hash -0.32553251)))
(is (= (hash -0.0000032553251) (hash -0.0000032553251)))))

(deftest test-cljs-3290
(testing "JS Symbol hash"
(let [s (.for js/Symbol "foo")]
(is (number? (hash s)))
(is (== (hash s) (hash s)))
(let [m {s 2}]
(is (== 2 (get m s)))))))

0 comments on commit 4defb9e

Please sign in to comment.