Add method to add a single string into Sets

This avoids creating and discarding a StringSet just to pass the parameter
This commit is contained in:
Bryan Boreham
2018-07-16 20:16:59 +00:00
parent 761fafe61b
commit 0d2409c72c
5 changed files with 20 additions and 5 deletions

View File

@@ -46,6 +46,21 @@ func (s Sets) Add(key string, value StringSet) Sets {
}
}
// AddString adds a single string under a key, creating a new StringSet if necessary.
func (s Sets) AddString(key string, str string) Sets {
if s.psMap == nil {
s = emptySets
}
value, found := s.Lookup(key)
if found && value.Contains(str) {
return s
}
value = value.Add(str)
return Sets{
psMap: s.psMap.Set(key, value),
}
}
// Delete the given set from the Sets.
func (s Sets) Delete(key string) Sets {
if s.psMap == nil {