-
Notifications
You must be signed in to change notification settings - Fork 0
xutil
omeyang edited this page Sep 17, 2026
·
1 revision
稳定性:Stable · 覆盖率:100.0% · 源码:
pkg/util/xutil
泛型小工具。当前仅 If 三目函数。
- 简化某些三元表达(Go 没有三目运算符)
import "github.com/omeyang/xkit/pkg/util/xutil"
x := xutil.If(cond, "yes", "no")
// 注意:trueVal 与 falseVal 都会被求值,没有短路!| 名称 | 说明 |
|---|---|
If[T any](cond bool, trueVal, falseVal T) T |
类型安全三目 |
-
无短路:Go 函数参数必先求值,不像 C
?:短路 - 简单优先:刻意保持小,扩张需 ADR