| type | since v0.0-1424 | Edit |
(UUID. uuid __hash)A type representing a universally unique identifier (UUID).
Use uuid or #uuid literal to create one.
;; Can be used to generate UUIDs but cljs.core/uuid is preferred
(UUID. (str (random-uuid)))
=> #uuid "d9b3d2a1-3f2a-4662-ae48-bfd7fe39e2a6"
;; UUID allows manual setting of hash values, which can make two otherwise
;; identical UUIDs no longer equal
(def nil-uuid #uuid "00000000-0000-0000-0000-000000000000")
(def custom-hash-nil-uuid (UUID. #uuid "00000000-0000-0000-0000-000000000000" 13))
(= nil-uuid #uuid "00000000-0000-0000-0000-000000000000")
=> true
(= custom-hash-nil-uuid #uuid "00000000-0000-0000-0000-000000000000")
=> false
(hash custom-hash-nil-uuid)
=> 13
(hash nil-uuid)
=> 1297391103
(deftype UUID [uuid ^:mutable __hash]
IUUID
Object
(toString [_] uuid)
(equiv [this other]
(-equiv this other))
IEquiv
(-equiv [_ other]
(and (implements? IUUID other) (identical? uuid (.-uuid other))))
IPrintWithWriter
(-pr-writer [_ writer _]
(-write writer (str_ "#uuid \"" uuid "\"")))
IHash
(-hash [this]
(when (nil? __hash)
(set! __hash (hash uuid)))
__hash)
IComparable
(-compare [this other]
(if (instance? UUID other)
(garray/defaultCompare uuid (.-uuid other))
(throw (js/Error. (str_ "Cannot compare " this " to " other))))))