diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2022-06-26 19:55:49 -0600 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2022-06-26 19:55:49 -0600 |
commit | 502cdc72771de93ce41e2a00bc201fc488603f59 (patch) | |
tree | d8b7bc9890d0f8f8069c70376220ab54daae52f7 /pkg/util | |
parent | e6b7c243462b1412390d0048dafe3430d07c05be (diff) |
better volume!
Diffstat (limited to 'pkg/util')
-rw-r--r-- | pkg/util/generic.go | 15 |
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 |