Skip to content

Commit 8f063a4

Browse files
jeffwidmandeckarep
authored andcommitted
Make NewThreadUnsafeSet() take optional vals.
This makes the API a bit cleaner, and matches the signature of `NewSet()`. Fix #80
1 parent d0d9122 commit 8f063a4

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

set.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ type Set[T comparable] interface {
175175
UnmarshalJSON(b []byte) error
176176
}
177177

178-
// NewSet creates and returns a reference to an empty set. Operations
179-
// on the resulting set are thread-safe.
178+
// NewSet creates and returns a new set with the given elements.
179+
// Operations on the resulting set are thread-safe.
180180
func NewSet[T comparable](vals ...T) Set[T] {
181181
s := newThreadSafeSet[T]()
182182
for _, item := range vals {
@@ -198,10 +198,13 @@ func NewSetFromSlice[T comparable](v []T) Set[T] {
198198
return s
199199
}
200200

201-
// NewThreadUnsafeSet creates and returns a reference to an empty set.
201+
// NewThreadUnsafeSet creates and returns a new set with the given elements.
202202
// Operations on the resulting set are not thread-safe.
203-
func NewThreadUnsafeSet[T comparable]() Set[T] {
203+
func NewThreadUnsafeSet[T comparable](vals ...T) Set[T] {
204204
s := newThreadUnsafeSet[T]()
205+
for _, item := range vals {
206+
s.Add(item)
207+
}
205208
return &s
206209
}
207210

0 commit comments

Comments
 (0)