-
Notifications
You must be signed in to change notification settings - Fork 2
/
predicates.go
127 lines (115 loc) · 2.97 KB
/
predicates.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package option
// Bool Predicates
// isTrue returns option value if option value is true
func IsTrue() Predicate {
return func(value interface{}) (result bool) {
if value, ok := value.(bool); ok == true {
result = value == true
} else {
result = false
}
return
}
}
// isFalse returns option value if option value is false
func IsFalse() Predicate {
return func(value interface{}) (result bool) {
if value, ok := value.(bool); ok == true {
result = value == false
} else {
result = false
}
return
}
}
// string Predicates
// EqualString returns option value if option value is equal to inputValue
func EqualString(inputValue string) Predicate {
return func(value interface{}) (result bool) {
if stringB, ok := value.(string); ok == true {
result = inputValue == stringB
} else {
result = false
}
return
}
}
// int Predicates
// EqualInt returns option value if option value is equal to inputValue
func EqualInt(inputValue int) Predicate {
return func(value interface{}) (result bool) {
if numB, ok := value.(int); ok == true {
result = inputValue == numB
} else {
result = false
}
return
}
}
// GreaterIntThan returns option value if option value is greater than inputNum
func GreaterIntThan(inputNum int) Predicate {
return func(value interface{}) (result bool) {
if valueInt, ok := value.(int); ok == true {
result = valueInt > inputNum
} else {
result = false
}
return
}
}
// LesserIntThan returns option value if option value is lesser than inputNum
func LesserIntThan(inputNum int) Predicate {
return func(value interface{}) (result bool) {
if valueInt, ok := value.(int); ok == true {
result = valueInt < inputNum
} else {
result = false
}
return
}
}
// array Predicates
// ContainsElemIntArray returns option value if inputNum is present
func ContainsElemIntArray(inputNum int) Predicate {
return func(value interface{}) (result bool) {
if arrayB, ok := value.([]int); ok == true {
result, _ = findInt(arrayB, inputNum)
}
return
}
}
// ContainsElemFloat64Array returns option value if inputFloat64 is present
func ContainsElemFloat64Array(inputFloat64 float64) Predicate {
return func(value interface{}) (result bool) {
if floatB, ok := value.([]float64); ok == true {
result, _ = findFloat64(floatB, inputFloat64)
}
return
}
}
// ContainsElemStringArray returns option value if inputString is present
func ContainsElemStringArray(inputString string) Predicate {
return func(value interface{}) (result bool) {
if arrayB, ok := value.([]string); ok == true {
result, _ = findString(arrayB, inputString)
}
return
}
}
// ContainsElemBoolArray returns option value if inputBool is present
func ContainsElemBoolArray(inputBool bool) Predicate {
return func(value interface{}) bool {
var result bool
if arrayB, ok := value.([]bool); ok == true {
for _, v := range arrayB {
if v == inputBool {
result = true
break
} else {
result = false
}
}
}
return result
}
}