diff --git a/condition/condition.go b/condition/condition.go index 061d8ad..57bb1f9 100644 --- a/condition/condition.go +++ b/condition/condition.go @@ -67,11 +67,11 @@ func Nand[T, U any](a T, b U) bool { return !Bool(a) || !Bool(b) } -// TernaryOperator if true return trueValue else return falseValue -func TernaryOperator[T any](isTrue bool, trueValue T, falseValue T) T { - if isTrue { - return trueValue +// TernaryOperator checks the value of param `isTrue`, if true return ifValue else return elseValue +func TernaryOperator[T, U any](isTrue T, ifValue U, elseValue U) U { + if Bool(isTrue) { + return ifValue } else { - return falseValue + return elseValue } } diff --git a/docs/condition.md b/docs/condition.md index 2cbb11c..3f25b5c 100644 --- a/docs/condition.md +++ b/docs/condition.md @@ -233,12 +233,12 @@ func main() { ### TernaryOperator -

Checks the value of param `isTrue`, if true return trueValue else return falseValue

+

Checks the value of param `isTrue`, if true return ifValue else return elseValue

Signature: ```go -func TernaryOperator[T any](isTrue bool, trueValue T, falseValue T) T +func TernaryOperator[T, U any](isTrue T, ifValue U, elseValue U) U ``` Example: diff --git a/docs/condition_zh-CN.md b/docs/condition_zh-CN.md index 54fada4..ac6e996 100644 --- a/docs/condition_zh-CN.md +++ b/docs/condition_zh-CN.md @@ -237,7 +237,7 @@ func main() { 函数签名: ```go -func TernaryOperator[T any](isTrue bool, trueValue T, falseValue T) T +func TernaryOperator[T, U any](isTrue T, ifValue U, elseValue U) U ``` 例子: