deckarep / golang-set

A simple, battle-tested and generic set type for the Go language. Trusted by Docker, 1Password, Ethereum and Hashicorp.
Other
4.15k stars 274 forks source link

[Question] NewSet vs NewSetWith #78

Closed ashwek closed 2 years ago

ashwek commented 2 years ago

How is NewSet different from NewSetWith?

https://github.com/deckarep/golang-set/blob/645e1ba83b7fdd0baab3f586c30a4d1619c71f99/set.go#L178-L180

https://github.com/deckarep/golang-set/blob/645e1ba83b7fdd0baab3f586c30a4d1619c71f99/set.go#L188-L190

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 commented 2 years ago

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 commented 2 years ago

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