-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathconditions.go
59 lines (50 loc) · 1.03 KB
/
conditions.go
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
package stateswitch
type not struct {
operand Condition
}
func (n not) do(stateSwitch StateSwitch, args TransitionArgs) (bool, error) {
b, err := n.operand(stateSwitch, args)
if err != nil {
return false, err
}
return !b, nil
}
func Not(operand Condition) Condition {
return not{operand: operand}.do
}
type and struct {
operands []Condition
}
func (a and) do(stateSwitch StateSwitch, args TransitionArgs) (bool, error) {
for _, o := range a.operands {
b, err := o(stateSwitch, args)
if err != nil {
return false, err
}
if !b {
return false, nil
}
}
return true, nil
}
func And(operands ...Condition) Condition {
return and{operands: operands}.do
}
type or struct {
operands []Condition
}
func (or or) do(stateSwitch StateSwitch, args TransitionArgs) (bool, error) {
for _, o := range or.operands {
b, err := o(stateSwitch, args)
if err != nil {
return false, err
}
if b {
return true, nil
}
}
return false, nil
}
func Or(operands ...Condition) Condition {
return or{operands: operands}.do
}