From 70cdb7be5fb47d8fcd2dff2eba93e4c27b0c587c Mon Sep 17 00:00:00 2001 From: muXxer Date: Thu, 2 Nov 2023 10:05:41 +0100 Subject: [PATCH] Add Remove func to Features and UnlockConditions --- feat.go | 12 ++++++++++++ unlock_cond.go | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/feat.go b/feat.go index 8bb9a77aa..145cad65c 100644 --- a/feat.go +++ b/feat.go @@ -157,6 +157,18 @@ func (f *Features[T]) Upsert(feature T) { *f = append(*f, feature) } +// Remove removes the given feature if it exists. +func (f *Features[T]) Remove(featureType FeatureType) bool { + for i, ele := range *f { + if ele.Type() == featureType { + *f = append((*f)[:i], (*f)[i+1:]...) + return true + } + } + + return false +} + // Sort sorts the Features in place by type. func (f Features[T]) Sort() { sort.Slice(f, func(i, j int) bool { return f[i].Type() < f[j].Type() }) diff --git a/unlock_cond.go b/unlock_cond.go index d760a85ba..5c50c816e 100644 --- a/unlock_cond.go +++ b/unlock_cond.go @@ -181,6 +181,18 @@ func (f *UnlockConditions[T]) Upsert(unlockCondition T) { *f = append(*f, unlockCondition) } +// Remove removes the given unlock condition if it exists. +func (f *UnlockConditions[T]) Remove(unlockConditionType UnlockConditionType) bool { + for i, ele := range *f { + if ele.Type() == unlockConditionType { + *f = append((*f)[:i], (*f)[i+1:]...) + return true + } + } + + return false +} + // Sort sorts the UnlockConditions in place by type. func (f UnlockConditions[T]) Sort() { sort.Slice(f, func(i, j int) bool { return f[i].Type() < f[j].Type() })