1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-11 16:22:26 +08:00

feat: add Ternary

This commit is contained in:
dudaodong
2024-11-08 14:20:35 +08:00
parent 08f14d2b08
commit de877e5278
5 changed files with 90 additions and 10 deletions

View File

@@ -72,10 +72,17 @@ func Nand[T, U any](a T, b U) bool {
// TernaryOperator checks the value of param `isTrue`, if true return ifValue else return elseValue.
// Play: https://go.dev/play/p/ElllPZY0guT
func TernaryOperator[T, U any](isTrue T, ifValue U, elseValue U) U {
func Ternary[T, U any](isTrue T, ifValue U, elseValue U) U {
if Bool(isTrue) {
return ifValue
} else {
return elseValue
}
}
// TernaryOperator checks the value of param `isTrue`, if true return ifValue else return elseValue.
// Play: https://go.dev/play/p/ElllPZY0guT
// Deprecated: Use Ternary instead.
func TernaryOperator[T, U any](isTrue T, ifValue U, elseValue U) U {
return Ternary(isTrue, ifValue, elseValue)
}