diff --git a/docs/data/core-withoutnth.md b/docs/data/core-withoutnth.md index e33cb562b..2b6a57225 100644 --- a/docs/data/core-withoutnth.md +++ b/docs/data/core-withoutnth.md @@ -13,7 +13,7 @@ similarHelpers: - core#slice#dropbyindex position: 140 signatures: - - "func WithoutNth[T comparable, Slice ~[]T](collection Slice, nths ...int) Slice" + - "func WithoutNth[T any, Slice ~[]T](collection Slice, nths ...int) Slice" --- Returns a slice excluding the elements at the given indexes. diff --git a/docs/data/it-withoutnth.md b/docs/data/it-withoutnth.md index 912bed811..fc2e439cd 100644 --- a/docs/data/it-withoutnth.md +++ b/docs/data/it-withoutnth.md @@ -5,7 +5,7 @@ sourceRef: it/intersect.go#L253 category: iter subCategory: intersect signatures: - - "func WithoutNth[T comparable, I ~func(func(T) bool)](collection I, nths ...int) I" + - "func WithoutNth[T any, I ~func(func(T) bool)](collection I, nths ...int) I" playUrl: "https://go.dev/play/p/KGE7Lpsk18P" variantHelpers: - iter#intersect#withoutnth diff --git a/it/intersect.go b/it/intersect.go index 603b084c3..80f196972 100644 --- a/it/intersect.go +++ b/it/intersect.go @@ -250,7 +250,7 @@ func WithoutBy[T any, K comparable, I ~func(func(T) bool)](collection I, transfo // WithoutNth returns a sequence excluding the nth value. // Will allocate a map large enough to hold all distinct nths. // Play: https://go.dev/play/p/KGE7Lpsk18P -func WithoutNth[T comparable, I ~func(func(T) bool)](collection I, nths ...int) I { +func WithoutNth[T any, I ~func(func(T) bool)](collection I, nths ...int) I { set := lo.Keyify(nths) return RejectI(collection, func(_ T, index int) bool { return lo.HasKey(set, index) }) } diff --git a/it/intersect_test.go b/it/intersect_test.go index 385982cf9..2d73d8283 100644 --- a/it/intersect_test.go +++ b/it/intersect_test.go @@ -517,6 +517,17 @@ func TestWithoutNth(t *testing.T) { }) } +func TestWithoutNthNonComparable(t *testing.T) { + t.Parallel() + is := assert.New(t) + + // Slices are not comparable; WithoutNth should accept T any (not T comparable) + // since it only operates on indices. + input := slices.Values([][]int{{1, 2}, {3, 4}, {5, 6}}) + result := slices.Collect(WithoutNth(input, 1)) + is.Equal([][]int{{1, 2}, {5, 6}}, result) +} + func TestElementsMatch(t *testing.T) { t.Parallel()