Conversation
XQ-Gang
commented
Jul 6, 2025
- add ContainsBy
- add OrO
- goption/gresult不依赖别的包,防止循环依赖
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #18 +/- ##
==========================================
+ Coverage 95.79% 96.13% +0.34%
==========================================
Files 34 34
Lines 4443 4451 +8
==========================================
+ Hits 4256 4279 +23
+ Misses 144 131 -13
+ Partials 43 41 -2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Option。类似 gsync中的LoadO、gconv中的ToR
| func Err[T any](e error) R[T] { | ||
| if gvalue.IsNil(e) { | ||
| if reflect.ValueOf(e).IsNil() { | ||
| panic(fmt.Errorf("expected a non-nil error, but found nil error with type %T", e)) |
There was a problem hiding this comment.
想说这样性能会差不少,转头一看 gvalue.IsNil 也已经是反射了(
There was a problem hiding this comment.
有个问题,原来的gvalue.IsNil()识别不了nil slice
There was a problem hiding this comment.
场景是啥?我印象 var t []T 和 var t = []T{} 在使用上应该完全没区别才对?(或者说不会导致什么问题)
There was a problem hiding this comment.
从使用上,我也觉得不应该使用 IsNil 或者直接 == nil 来区分空slice。
但是从语义上,IsNil应该能区分出slice是否是nil,之前完全区分不出来,误导性比较强。
之前的实现:
var t []T
gvalue.IsNil(t) // falseThere was a problem hiding this comment.
空 slice 就不是 nil 吧?
var s []int
assert.True(t, IsNil(s))
var s2 = []int{}
assert.False(t, IsNil(s2))可以补一个测试。
| r.err = errors.New(*jr.Err) | ||
| } else { | ||
| r.val = *jr.Val | ||
| r.err = nil |
There was a problem hiding this comment.
这里不能直接删除吧?把一个 var r Result 传给 json.Unarmal(data, &v) 后,是需要清除原来的值的?
这么一看发现原来也有问题 😂,应该在 L205 之前就把 r 清空了。
| } | ||
| return goption.Nil[T]() | ||
| } | ||
|
|
There was a problem hiding this comment.
感觉这个函数名字不太直观,名字也不太清晰(还以为是 Or0)。能给一些更 real world 的用例么?
There was a problem hiding this comment.
主要是想迁移原先的choose.NotZero
There was a problem hiding this comment.
按原来规范可能叫 OfNonZero 比较好?不过还是不如 choose 直观。
