Four years after generics landed, a Go working group has proposed container/set, container/hash, container/ordered and heap/v2 for the standard library, targeting Go 1.28.

Read the full story: Go Finally Proposes Generic Sets and Maps for the Stdlib →

Transcript

Go got generics in twenty twenty two and still has no set type. That changes with proposal eighty five ninety, opened this week by a working group that reads like a roll call of the people who built the language. Griesemer, Donovan, Ian Lance Taylor. Four packages, targeting Go one twenty eight. If your elements are comparable you get container slash set, backed by a map. If they're not, or you need equality that isn't double equals, you supply a hash function and use container slash hash. If iteration order matters, container slash ordered gives you a balanced tree. So why did this take four years? Writing a set is a weekend project. Standardizing one runs into what's called the binary method problem. A Union method on a hash set takes a hash set. On a tree set it takes a tree set. Both are sets with a Union method, but no interface can describe either one, because the argument type moves with the receiver. The working group's answer is the interesting bit. They ship the concrete types and keep the abstract interfaces unexported, on purpose, until people have used them. Under Go's compatibility promise an exported interface is permanent. A missing one is cheaper than a wrong one.