diff --git a/slice/slice.go b/slice/slice.go index 3983ad0..25cb081 100644 --- a/slice/slice.go +++ b/slice/slice.go @@ -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 { diff --git a/slice/slice_test.go b/slice/slice_test.go index 45a97f0..257f52e 100644 --- a/slice/slice_test.go +++ b/slice/slice_test.go @@ -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}