Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/data/core-withoutnth.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion docs/data/it-withoutnth.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion it/intersect.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) })
}
Expand Down
11 changes: 11 additions & 0 deletions it/intersect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down