diff --git a/container/set.go b/container/set.go index e26fd07..6a76706 100644 --- a/container/set.go +++ b/container/set.go @@ -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