From 22b0e6fd80b82c942d8842dc45fcdfd027aaff03 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 26 Jun 2022 19:55:49 -0600 Subject: better volume! --- pkg/util/generic.go | 15 +++++++++++++-- 1 file 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 -- cgit v1.2.3-2-g168b