Add a variadic constructor for container.Set
This commit is contained in:
parent
0f903cc8ec
commit
e6a94c487e
@ -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
|
||||
|
Reference in New Issue
Block a user