Skip to content

Commit 92b1386

Browse files
committed
feat: add
1 parent 9209973 commit 92b1386

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

pkg/if_expression/type_gen.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func main() {
2727
start_pos := strings.Index(string(filedata), packageName)
2828
w.WriteString(string(filedata)[start_pos : start_pos+len(packageName)])
2929

30-
ts := []string{"Byte", "Complex64", "Complex128", "Float32", "Float64", "Int", "Int8", "Int16", "Int32", "Rune", "String", "Uint", "Uint8", "Uint16", "Uint32", "Uint64", "Uintptr"}
30+
ts := []string{"Bool", "Byte", "Complex64", "Complex128", "Float32", "Float64", "Int", "Int8", "Int16", "Int32", "Rune", "String", "Uint", "Uint8", "Uint16", "Uint32", "Uint64", "Uintptr"}
3131

3232
for _, upper := range ts {
3333
lower := strings.ToLower(upper)

pkg/if_expression/types.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,61 @@
11
package if_expression
22

3+
// ReturnBool
4+
// @Description: if实现的三元表达式,返回结果是bool
5+
// @param boolExpression: 表达式,最终返回一个布尔值
6+
// @param trueReturnValue: 当boolExpression返回值为true的时候返回的bool
7+
// @param falseReturnValue: 当boolExpression返回值为false的时候返回的bool
8+
// @return bool: 三元表达式的结果,为trueReturnValue或者falseReturnValue中的一个
9+
func ReturnBool(boolExpression bool, trueReturnValue, falseReturnValue bool) bool {
10+
if boolExpression {
11+
return trueReturnValue
12+
} else {
13+
return falseReturnValue
14+
}
15+
}
16+
17+
// ReturnBoolSlice
18+
// @Description: if实现的三元表达式,返回结果是[]bool
19+
// @param boolExpression: 表达式,最终返回一个布尔值
20+
// @param trueReturnValue: 当boolExpression返回值为true的时候返回的[]bool
21+
// @param falseReturnValue: 当boolExpression返回值为false的时候返回的[]bool
22+
// @return []bool: 三元表达式的结果,为trueReturnValue或者falseReturnValue中的一个
23+
func ReturnBoolSlice(boolExpression bool, trueReturnValue, falseReturnValue []bool) []bool {
24+
if boolExpression {
25+
return trueReturnValue
26+
} else {
27+
return falseReturnValue
28+
}
29+
}
30+
31+
// ReturnBoolPointer
32+
// @Description: if实现的三元表达式,返回结果是*bool
33+
// @param boolExpression: 表达式,最终返回一个布尔值
34+
// @param trueReturnValue: 当boolExpression返回值为true的时候返回的*bool
35+
// @param falseReturnValue: 当boolExpression返回值为false的时候返回的*bool
36+
// @return *bool: 三元表达式的结果,为trueReturnValue或者falseReturnValue中的一个
37+
func ReturnBoolPointer(boolExpression bool, trueReturnValue, falseReturnValue *bool) *bool {
38+
if boolExpression {
39+
return trueReturnValue
40+
} else {
41+
return falseReturnValue
42+
}
43+
}
44+
45+
// ReturnBoolPointerSlice
46+
// @Description: if实现的三元表达式,返回结果是[]*bool
47+
// @param boolExpression: 表达式,最终返回一个布尔值
48+
// @param trueReturnValue: 当boolExpression返回值为true的时候返回的[]*bool
49+
// @param falseReturnValue: 当boolExpression返回值为false的时候返回的[]*bool
50+
// @return []*bool: 三元表达式的结果,为trueReturnValue或者falseReturnValue中的一个
51+
func ReturnBoolPointerSlice(boolExpression bool, trueReturnValue, falseReturnValue []*bool) []*bool {
52+
if boolExpression {
53+
return trueReturnValue
54+
} else {
55+
return falseReturnValue
56+
}
57+
}
58+
359
// ReturnByte
460
// @Description: if实现的三元表达式,返回结果是byte
561
// @param boolExpression: 表达式,最终返回一个布尔值

0 commit comments

Comments
 (0)