fix(slice): handle Intersection without inputs (#366)

This commit is contained in:
Yusuf Efe authored and GitHub committed 2026-10-23 20:54:26 +08:00
1 parent 129da3f2ed
commit f220ea4c3f
2 files changed
+4

No files matched your search

+3
View File
@@ -1019,6 +1019,9 @@ func Merge[T any](slices ...[]T) []T {
// Play: https://go.dev/play/p/anJXfB5wq_t
func Intersection[T comparable](slices ...[]T) []T {
result := []T{}
if len(slices) == 0 {
return result
}
elementCount := make(map[T]int)
for _, slice := range slices {
+1
View File
@@ -1105,6 +1105,7 @@ func TestIntersection(t *testing.T) {
t.Parallel()
assert := internal.NewAssert(t, "TestIntersection")
assert.Equal([]int{}, Intersection[int]())
s1 := []int{1, 2, 2, 3}
s2 := []int{1, 2, 3, 4}