mirror of
https://github.com/samber/lo.git
synced 2025-09-27 04:15:58 +08:00
Add function Without which return slice with slice all elements not i… (#142)
* Add function Without which return slice with slice all elements not in another * feat(Without): inverse args and use variadic argment for excluding items Co-authored-by: Samuel Berthe <dev@samuel-berthe.fr>
This commit is contained in:
11
intersect.go
11
intersect.go
@@ -175,3 +175,14 @@ func Union[T comparable](list1 []T, list2 []T) []T {
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// Without returns slice excluding all given values.
|
||||
func Without[T comparable](collection []T, exclude ...T) []T {
|
||||
result := make([]T, 0, len(collection))
|
||||
for _, e := range collection {
|
||||
if !Contains(exclude, e) {
|
||||
result = append(result, e)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
Reference in New Issue
Block a user