Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add WithoutBy #515

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Prev Previous commit
feat: replace Without implementation by WithoutBy
  • Loading branch information
nicklaus-dev committed Aug 23, 2024
commit c102c037381366a60046a2ea59f37aa8be79636a
8 changes: 1 addition & 7 deletions intersect.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,7 @@ func Union[T comparable, Slice ~[]T](lists ...Slice) Slice {

// Without returns slice excluding all given values.
func Without[T comparable, Slice ~[]T](collection Slice, exclude ...T) Slice {
result := make(Slice, 0, len(collection))
for i := range collection {
if !Contains(exclude, collection[i]) {
result = append(result, collection[i])
}
}
return result
return WithoutBy(collection, func(item T) T { return item }, exclude...)
}

// WithoutBy filters a slice by excluding elements whose extracted keys match any in the exclude list.
Expand Down