From f220ea4c3fbe8812d61c4a15cdae438e83babc38 Mon Sep 17 00:00:00 2001 From: Yusuf Efe <120668197+yuefdev@users.noreply.github.com> Date: Fri, 23 Oct 2026 15:54:26 +0300 Subject: [PATCH] fix(slice): handle Intersection without inputs (#366) --- slice/slice.go | 3 +++ slice/slice_test.go | 1 + 2 files changed, 4 insertions(+) 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}