Skip to content

Commit

Permalink
Add Remove func to Features and UnlockConditions
Browse files Browse the repository at this point in the history
  • Loading branch information
muXxer committed Nov 2, 2023
1 parent 4f987f5 commit 70cdb7b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
12 changes: 12 additions & 0 deletions feat.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() })
Expand Down
12 changes: 12 additions & 0 deletions unlock_cond.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() })
Expand Down

0 comments on commit 70cdb7b

Please sign in to comment.