golang模拟三元运算符
func If[T any](cond bool, trueValue, falseValue T) T {
if cond {
return trueValue
} else {
return falseValue
}
}
func TestIf(t *testing.T) {
fmt.Println(If(1 >= 2, "gt", "lt"))
}
func If[T any](cond bool, trueValue, falseValue T) T {
if cond {
return trueValue
} else {
return falseValue
}
}
func TestIf(t *testing.T) {
fmt.Println(If(1 >= 2, "gt", "lt"))
}