1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-12 08:42:29 +08:00

refactor: fix bad code smell

This commit is contained in:
dudaodong
2022-11-30 11:20:13 +08:00
parent 5692982dd1
commit 5466a23019

View File

@@ -20,10 +20,10 @@ func (s Set[T]) Add(items ...T) {
// AddIfNotExist checks if item exists in the set, // AddIfNotExist checks if item exists in the set,
// it adds the item to set and returns true if it does not exist in the set, // it adds the item to set and returns true if it does not exist in the set,
// or else it does nothing and returns false. // or else it does nothing and returns false.
func (s Set[T]) AddIfNotExist(value T) bool { func (s Set[T]) AddIfNotExist(item T) bool {
if !s.Contain(value) { if !s.Contain(item) {
if _, ok := s[value]; !ok { if _, ok := s[item]; !ok {
s[value] = struct{}{} s[item] = struct{}{}
return true return true
} }
} }
@@ -45,9 +45,9 @@ func (s Set[T]) AddIfNotExistBy(item T, checker func(element T) bool) bool {
return false return false
} }
// Contain checks if set contains value or not // Contain checks if set contains item or not
func (s Set[T]) Contain(value T) bool { func (s Set[T]) Contain(item T) bool {
_, ok := s[value] _, ok := s[item]
return ok return ok
} }
@@ -86,7 +86,7 @@ func (s Set[T]) Equal(other Set[T]) bool {
} }
// Iterate call function by every element of set // Iterate call function by every element of set
func (s Set[T]) Iterate(fn func(value T)) { func (s Set[T]) Iterate(fn func(item T)) {
for v := range s { for v := range s {
fn(v) fn(v)
} }