-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbool.go
45 lines (41 loc) · 1.47 KB
/
bool.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
package if_expression
// ReturnBool
// @Description: if实现的三元表达式,返回结果是布尔bool
// @param boolExpression: 表达式,最终返回一个布尔值
// @param trueReturnValue: 当boolExpression返回值为true的时候返回的bool值
// @param falseReturnValue: 当boolExpression返回值为false的时候返回的bool值
// @return bool: 三元表达式的结果
func ReturnBool(boolExpression bool, trueReturnValue, falseReturnValue bool) bool {
if boolExpression {
return trueReturnValue
} else {
return falseReturnValue
}
}
func ReturnBoolSlice(boolExpression bool, trueReturnValue, falseReturnValue []bool) []bool {
if boolExpression {
return trueReturnValue
} else {
return falseReturnValue
}
}
// ReturnBoolPointer
// @Description: if实现的三元表达式,返回结果是布尔指针*bool
// @param boolExpression: 表达式,最终返回一个布尔值
// @param trueReturnValue: 当boolExpression返回值为true的时候返回的*bool值
// @param falseReturnValue: 当boolExpression返回值为false的时候返回的*bool值
// @return *bool: 三元表达式的结果
func ReturnBoolPointer(boolExpression bool, trueReturnValue, falseReturnValue *bool) *bool {
if boolExpression {
return trueReturnValue
} else {
return falseReturnValue
}
}
func ReturnBoolPointerSlice(boolExpression bool, trueReturnValue, falseReturnValue []*bool) []*bool {
if boolExpression {
return trueReturnValue
} else {
return falseReturnValue
}
}