add StringSet.HasAny

This commit is contained in:
deads2k 2015-04-29 11:24:38 -04:00
parent 8fa21ebd62
commit f258717f26
2 changed files with 22 additions and 0 deletions

View File

@ -75,6 +75,16 @@ func (s StringSet) HasAll(items ...string) bool {
return true
}
// HasAny returns true if any items are contained in the set.
func (s StringSet) HasAny(items ...string) bool {
for _, item := range items {
if s.Has(item) {
return true
}
}
return false
}
// Difference returns a set of objects that are not in s2
// For example:
// s1 = {1, 2, 3}

View File

@ -117,3 +117,15 @@ func TestStringSetDifference(t *testing.T) {
t.Errorf("Unexpected contents: %#v", d.List())
}
}
func TestStringSetHasAny(t *testing.T) {
a := NewStringSet("1", "2", "3")
if !a.HasAny("1", "4") {
t.Errorf("expected true, got false")
}
if a.HasAny("0", "4") {
t.Errorf("expected false, got true")
}
}