Add a variadic constructor for container.Set

This commit is contained in:
Sasha Koshka 2024-09-20 17:07:16 -04:00
parent 0f903cc8ec
commit e6a94c487e

View File

@ -3,6 +3,15 @@ package ucontainer
// Set is a set of unique items, built on top of map.
type Set[T comparable] map[T] struct { }
// NewSet creates a new set that contains all specified items.
func NewSet[T comparable] (items ...T) Set[T] {
set := make(Set[T])
for _, item := range items {
set.Add(item)
}
return set
}
// Empty returns true if there are no items in the set.
func (set Set[T]) Empty () bool {
return set == nil || len(set) == 0