mirror of
https://github.com/charlienet/go-mixed.git
synced 2025-07-18 00:22:41 +08:00
expr
This commit is contained in:
9
expr/expr.go
Normal file
9
expr/expr.go
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package expr
|
||||||
|
|
||||||
|
// 如为真返回参数一,否则返回参数二
|
||||||
|
func If[T any](e bool, v1, v2 T) T {
|
||||||
|
if e {
|
||||||
|
return v1
|
||||||
|
}
|
||||||
|
return v2
|
||||||
|
}
|
9
expr/expr_test.go
Normal file
9
expr/expr_test.go
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package expr
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestIf(t *testing.T) {
|
||||||
|
v1 := 10
|
||||||
|
v2 := 4
|
||||||
|
t.Log(If(v1 > v2, v1, v2))
|
||||||
|
}
|
Reference in New Issue
Block a user