Golang proposal: container/: generic collection types
Go's Collections working group has unveiled a suite of new generic collection type proposals for Go 1.28, aiming to standardize common data structures long expressed manually or absent from the standard library. These additions leverage generics and iterators, promising improved ergonomics and functionality for Go developers. The proposals highlight Go's continued evolution towards a more feature-rich but still pragmatic language, sparking interest among its community for more robust built-in data handling.
The Lowdown
The Go Collections working group, established in late 2025, has released a comprehensive proposal for new generic collection types to be integrated into the standard library for Go 1.28. Guided by Go's core principles of pragmatism and simplicity, this initiative seeks to address the current scarcity of built-in collection types beyond basic slices and maps, offering more ergonomic and standardized solutions for common data structures.
Key proposals include:
- hash/maphash.Hasher: A standard interface for custom hash functions and equivalence relations, allowing non-comparable types (like slices) to be used as map keys.
- container/hash.Map[K,V]: A hash-based map utilizing the new custom hash functions.
- container/hash.Set[T]: A corresponding hash-based set.
- container/set.Set[T]: A canonical set type for comparable elements, providing a more convenient and unambiguous alternative to
map[T]boolormap[T]struct{}. - container/mapset: Helper functions for manipulating 'legacy' map-based sets in existing code, mirroring the methods of
set.Set. - container/ordered.Map[K,V]: An ordered mapping, currently implemented with a balanced binary tree, offering better performance for range queries.
- container/heap/v2.Heap: A generic binary heap API designed to be more user-friendly than the existing standard library heap.
The proposal also outlines abstract Collection, Map, and Set constraint interfaces (currently unexported) that will serve as documentation for Go's conventions and ensure consistency across implementations. The design emphasizes returning as much information as possible from methods (e.g., whether a mutation changed collection size, previous values for map operations) and carefully balances concrete interface methods with generic helper functions to manage implementation burden and optimize performance. While initial implementations prioritize API and asymptotic performance, future optimizations for constant factors are anticipated, with additional collection types like insertion-ordered hash maps and stacks also under consideration.