On Fri, 30 Dec 2016 11:26:16 -0800 (PST) buchanae.o...@gmail.com wrote: > On Saturday, December 3, 2011 at 1:32:02 AM UTC-8, James Chow wrote: > > > > I used "set" in java and c++, why there is no such container in > > golang pkg-tree? > > > Back to the original question, container/set seems like a great > addition. It could have a nicer interface than map[T]U and a single > best implementation. Can we talk about whether the owners of that > package agree?
I may be wrong, but I think it's actually about Go not having generics: since map[T]U has built-in support from the compiler (as you can see, it is generic as its type is parameterized by T and U), you can use it easily. On the contrary, the prospective container/set *module* cannot expect this level of support from the compiler (it doesn't matter this module would have been provided as part of the runtime), so it would have to define all its methods in the terms of the interface{} type, and with that you will require the users of the package do type conversions when using it. Please look at the existing container/list module: while I do find it useful, quite many people think adding it was a mistake: the amount of boilerplate it can reduce for it could be balanced by the amount of it to actually use the module. Note that there exists 3rd-party projects like [1] which can be used along with codegen support [2] to provide custom type-safe set implementations for particular concrete types. See also the more recent [3] which appears to use the stock `go generate` command to achieve the same goal. 1. https://github.com/deckarep/golang-set 2. http://alikewise.com/gen/ 3. https://github.com/ncw/gotemplate -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.