fix(package): [stream] do not call less with a zero value in Max and Min (#422)

* fix(package): [stream] do not call less with a zero value in Max and Min

* test(package): [stream] cover Max and Min with pointer items
This commit is contained in:
Lee Sang Gyu authored and GitHub committed 2026-11-09 12:27:08 +08:00
1 parent 9c56f5f525
commit afc0d3c676
2 files changed
+19 -2

No files matched your search

+17
View File
@@ -423,3 +423,20 @@ func TestStream_ToMap(t *testing.T) {
assert.EqualValues(expected, m)
}
func TestStream_MaxMinDoNotCompareWithZeroValue(t *testing.T) {
assert := internal.NewAssert(t, "TestStream_MaxMinDoNotCompareWithZeroValue")
type Person struct {
Age int
}
s := FromSlice([]*Person{{Age: 20}, {Age: 10}, {Age: 30}})
max, ok := s.Max(func(a, b *Person) bool { return a.Age > b.Age })
assert.Equal(true, ok)
assert.Equal(30, max.Age)
min, ok := s.Min(func(a, b *Person) bool { return a.Age < b.Age })
assert.Equal(true, ok)
assert.Equal(10, min.Age)
}