summaryrefslogtreecommitdiff
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
commit22b0e6fd80b82c942d8842dc45fcdfd027aaff03 (patch)
tree18bba6d569a962d1077abceb9deae5305d65f61f
parent1e5e0aa0ecbade7c748cf920b405635e45b1796c (diff)
better volume!
-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