Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] NewSet vs NewSetWith #78

Closed
ashwek opened this issue Feb 17, 2022 · 2 comments · Fixed by #84
Closed

[Question] NewSet vs NewSetWith #78

ashwek opened this issue Feb 17, 2022 · 2 comments · Fixed by #84

Comments

@ashwek
Copy link

ashwek commented Feb 17, 2022

How is NewSet different from NewSetWith?

golang-set/set.go

Lines 178 to 180 in 645e1ba

// NewSet creates and returns a reference to an empty set. Operations
// on the resulting set are thread-safe.
func NewSet(s ...interface{}) Set {

golang-set/set.go

Lines 188 to 190 in 645e1ba

// NewSetWith creates and returns a new set with the given elements.
// Operations on the resulting set are thread-safe.
func NewSetWith(elts ...interface{}) Set {

According to NewSet's documentation, it returns reference to an empty set. But that's not true. It returns reference to a set with all the items passed in parameters.

That's exactly what NewSetWith does. So how are they different?

Am i missing something here?

@jeffwidman
Copy link
Contributor

I had the exact same question... @deckarep when you release the generics-compatible version, maybe take that opportunity to also cleanup the API slightly and remove NewSetWith()?

Would it also make sense to remove NewSetFromSlice([]elt) given that someone could write the NewSet([]elt...) and it'd be functionally equivalent and fewer characters... ??

@jeffwidman
Copy link
Contributor

jeffwidman commented Mar 27, 2022

This could easily be fixed by #83 combined with #84.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants