diff --git a/weightedrandom/weightedrandom.go b/weightedrandom/weightedrandom.go index 81aac63..173c496 100644 --- a/weightedrandom/weightedrandom.go +++ b/weightedrandom/weightedrandom.go @@ -98,3 +98,14 @@ func (wr *WeightRandom[T]) Get() (t T) { } return } + +// Cleanup deletes the items where the the function returns true +func (wr *WeightRandom[T]) Cleanup(f func(T) bool) { + nl := make(wflist[T], 0, wr.data.Len()) + for _, item := range wr.data { + if !f(item.value) { + nl = append(nl, item) + } + } + wr.data = nl +}