-
Notifications
You must be signed in to change notification settings - Fork 31
/
op.clj
65 lines (52 loc) · 1.37 KB
/
op.clj
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
(ns knossos.op
"Operations on operations!
An operation is comprised of a `process` with a `type` indicating whether it
is invoking, completing, failing, or noting progress of a function `f`,
called with an argument `value`. In addition, operations may have an `:index`
which identifies their position in a history, and carry extra keys.")
(defrecord Op [process type f value ^:int index])
(defn Op->map
"Turns an Op back into a plain old map"
[^Op op]
(when op (into {} op)))
(defn op
"Constructs a new operation for a history."
[process type f value]
(Op. process type f value -1))
(defn invoke
"Constructs an invocation op."
[process f value]
(op process :invoke f value))
(defn ok
"Constructs an OK op."
[process f value]
(op process :ok f value))
(defn fail
"Constructs a fail op."
[process f value]
(op process :fail f value))
(defn info
"Constructs an info op."
[process f value]
(op process :info f value))
(defn ok?
"Is this op OK?"
[op]
(identical? :ok (:type op)))
(defn invoke?
"Is this op an invocation?"
[op]
(identical? :invoke (:type op)))
(defn fail?
"Is this op a failure?"
[op]
(identical? :fail (:type op)))
(defn info?
"Is this op an informational message?"
[op]
(identical? :info (:type op)))
(defn same-process?
"Do A and B come from the same process?"
[a b]
(= (:process a)
(:process b)))