summaryrefslogtreecommitdiff
path: root/pkg/util
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2022-06-26 19:55:49 -0600
committerLuke Shumaker <lukeshu@lukeshu.com>2022-06-26 19:55:49 -0600
commit502cdc72771de93ce41e2a00bc201fc488603f59 (patch)
treed8b7bc9890d0f8f8069c70376220ab54daae52f7 /pkg/util
parente6b7c243462b1412390d0048dafe3430d07c05be (diff)
better volume!
Diffstat (limited to 'pkg/util')
-rw-r--r--pkg/util/generic.go15
1 files changed, 13 insertions, 2 deletions
diff --git a/pkg/util/generic.go b/pkg/util/generic.go
index 7ff2445..520d94e 100644
--- a/pkg/util/generic.go
+++ b/pkg/util/generic.go
@@ -13,12 +13,23 @@ func InSlice[T comparable](needle T, haystack []T) bool {
return false
}
-func RemoveFromSlice[T comparable](haystack []T, needle T) []T {
+func RemoveAllFromSlice[T comparable](haystack []T, needle T) []T {
for i, straw := range haystack {
if needle == straw {
return append(
haystack[:i],
- RemoveFromSlice(haystack[i+1], item)...)
+ RemoveAllFromSlice(haystack[i+1:], needle)...)
+ }
+ }
+ return haystack
+}
+
+func RemoveAllFromSliceFunc[T any](haystack []T, f func(T) bool) []T {
+ for i, straw := range haystack {
+ if f(straw) {
+ return append(
+ haystack[:i],
+ RemoveAllFromSliceFunc(haystack[i+1:], f)...)
}
}
return haystack