Skip to content

Commit 2bfe320

Browse files
tonskyswannodette
authored andcommitted
CLJS-1095: UUID to implement IComparable
1 parent 571cbff commit 2bfe320

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/cljs/cljs/core.cljs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9331,7 +9331,11 @@ Maps become Objects. Arbitrary keys are encoded to by key->js."
93319331

93329332
IHash
93339333
(-hash [this]
9334-
(goog.string/hashCode (pr-str this))))
9334+
(goog.string/hashCode (pr-str this)))
9335+
9336+
IComparable
9337+
(-compare [_ other]
9338+
(garray/defaultCompare uuid (.-uuid other))))
93359339

93369340
;;; ExceptionInfo
93379341

test/cljs/cljs/core_test.cljs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1629,6 +1629,12 @@
16291629
(get {(UUID. "550e8400-e29b-41d4-a716-446655440000") 42}
16301630
(UUID. "666e8400-e29b-41d4-a716-446655440000")
16311631
:not-at-all-found)))
1632+
(is (= -1 (compare (UUID. "550e8400-e29b-41d4-a716-446655440000")
1633+
(UUID. "666e8400-e29b-41d4-a716-446655440000"))))
1634+
(is (= 1 (compare (UUID. "550e8400-e29b-41d4-a716-446655440000")
1635+
(UUID. "550e8400-a29b-41d4-a716-446655440000"))))
1636+
(is (= 0 (compare (UUID. "550e8400-e29b-41d4-a716-446655440000")
1637+
(UUID. "550e8400-e29b-41d4-a716-446655440000"))))
16321638
))
16331639

16341640
(deftest test-comparable

0 commit comments

Comments
 (0)