-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathint.go
57 lines (53 loc) · 2.37 KB
/
int.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
package if_expression
// ReturnInt
// @Description: if实现的三元表达式,返回结果是int
// @param boolExpression: 表达式,最终返回一个布尔值
// @param trueReturnValue: 当boolExpression返回值为true的时候返回的int
// @param falseReturnValue: 当boolExpression返回值为false的时候返回的int
// @return int: 三元表达式的结果,为trueReturnValue或者falseReturnValue中的一个
func ReturnInt(boolExpression bool, trueReturnValue, falseReturnValue int) int {
if boolExpression {
return trueReturnValue
} else {
return falseReturnValue
}
}
// ReturnIntSlice
// @Description: if实现的三元表达式,返回结果是[]int
// @param boolExpression: 表达式,最终返回一个布尔值
// @param trueReturnValue: 当boolExpression返回值为true的时候返回的[]int
// @param falseReturnValue: 当boolExpression返回值为false的时候返回的[]int
// @return []int: 三元表达式的结果,为trueReturnValue或者falseReturnValue中的一个
func ReturnIntSlice(boolExpression bool, trueReturnValue, falseReturnValue []int) []int {
if boolExpression {
return trueReturnValue
} else {
return falseReturnValue
}
}
// ReturnIntPointer
// @Description: if实现的三元表达式,返回结果是*int
// @param boolExpression: 表达式,最终返回一个布尔值
// @param trueReturnValue: 当boolExpression返回值为true的时候返回的*int
// @param falseReturnValue: 当boolExpression返回值为false的时候返回的*int
// @return *int: 三元表达式的结果,为trueReturnValue或者falseReturnValue中的一个
func ReturnIntPointer(boolExpression bool, trueReturnValue, falseReturnValue *int) *int {
if boolExpression {
return trueReturnValue
} else {
return falseReturnValue
}
}
// ReturnIntPointerSlice
// @Description: if实现的三元表达式,返回结果是[]*int
// @param boolExpression: 表达式,最终返回一个布尔值
// @param trueReturnValue: 当boolExpression返回值为true的时候返回的[]*int
// @param falseReturnValue: 当boolExpression返回值为false的时候返回的[]*int
// @return []*int: 三元表达式的结果,为trueReturnValue或者falseReturnValue中的一个
func ReturnIntPointerSlice(boolExpression bool, trueReturnValue, falseReturnValue []*int) []*int {
if boolExpression {
return trueReturnValue
} else {
return falseReturnValue
}
}