mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-13 17:22:27 +08:00
refactor: change TernaryOperator signature
This commit is contained in:
@@ -67,11 +67,11 @@ func Nand[T, U any](a T, b U) bool {
|
|||||||
return !Bool(a) || !Bool(b)
|
return !Bool(a) || !Bool(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TernaryOperator if true return trueValue else return falseValue
|
// TernaryOperator checks the value of param `isTrue`, if true return ifValue else return elseValue
|
||||||
func TernaryOperator[T any](isTrue bool, trueValue T, falseValue T) T {
|
func TernaryOperator[T, U any](isTrue T, ifValue U, elseValue U) U {
|
||||||
if isTrue {
|
if Bool(isTrue) {
|
||||||
return trueValue
|
return ifValue
|
||||||
} else {
|
} else {
|
||||||
return falseValue
|
return elseValue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -233,12 +233,12 @@ func main() {
|
|||||||
|
|
||||||
|
|
||||||
### <span id="TernaryOperator">TernaryOperator</span>
|
### <span id="TernaryOperator">TernaryOperator</span>
|
||||||
<p>Checks the value of param `isTrue`, if true return trueValue else return falseValue</p>
|
<p>Checks the value of param `isTrue`, if true return ifValue else return elseValue</p>
|
||||||
|
|
||||||
<b>Signature:</b>
|
<b>Signature:</b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func TernaryOperator[T any](isTrue bool, trueValue T, falseValue T) T
|
func TernaryOperator[T, U any](isTrue T, ifValue U, elseValue U) U
|
||||||
```
|
```
|
||||||
<b>Example:</b>
|
<b>Example:</b>
|
||||||
|
|
||||||
|
|||||||
@@ -237,7 +237,7 @@ func main() {
|
|||||||
<b>函数签名:</b>
|
<b>函数签名:</b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func TernaryOperator[T any](isTrue bool, trueValue T, falseValue T) T
|
func TernaryOperator[T, U any](isTrue T, ifValue U, elseValue U) U
|
||||||
```
|
```
|
||||||
<b>例子:</b>
|
<b>例子:</b>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user