-
Notifications
You must be signed in to change notification settings - Fork 4
/
util.cljc
41 lines (34 loc) · 956 Bytes
/
util.cljc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
(ns com.fulcrologic.statecharts.util
#?(:clj
(:import (clojure.lang PersistentQueue)
(java.util UUID Date))))
(defn genid
"Generate a unique ID with a base prefix. Like `gensym` but returns a keyword."
[s] (keyword (str (gensym (name s)))))
(defn new-uuid []
#?(:clj (UUID/randomUUID)
:cljs (random-uuid)) )
(defn queue [& args]
(reduce conj
#?(:clj PersistentQueue/EMPTY
:cljs #queue [])
args))
(defn now-ms []
#?(:clj (inst-ms (Date.))
:cljs (inst-ms (js/Date.))))
(defn extend-key
"Extend the length of a keyword by turning the full original keyword into a namespace
and adding the given `new-name`.
E.g.
```
(extend-key :a \"b\") => :a/b
(extend-key :a/b \"c\") => :a.b/c
```
"
[k new-name]
(let [old-ns (namespace k)
nm (name k)
new-ns (if old-ns
(str old-ns "." nm)
nm)]
(keyword new-ns new-name)))