Go Generics
Concrete guidance for deciding when Go generics pay off, with constraint and type-alias rules and common pitfalls.
- CCM score
- 65 of 100
- skills.sh installs
- 1.1K
- GitHub stars
- 197
- last updated
- Aug 21, 2026
Own this skill? Claim it
What it does
- Covers when to use generics, decision flow against concrete types and interfaces, type parameter naming, constraint composition, and type aliases
- Includes bad and good code pairs showing premature generics, unnecessary wrappers, and over-constrained signatures
- Enforces a rule to start with concrete types and generalize only when a second type appears
- Designed for Go 1.18+ codebases; cross-references go-interfaces, go-declarations, go-documentation, and go-naming
Install
$ npx -y skills add cxuu/golang-skills --skill go-generics -yInstalls into .agents/skills for every agent it finds here, and .claude/skills for Claude Code.
Files
Go Generics and Type Parameters
Compatibility: Generics require Go 1.18+.
Resource Routing
references/CONSTRAINTS.md- Read when composing constraints, using type sets, or choosing between generics and interfaces.
When to Use Generics
Start with concrete types. Generalize only when a second type appears.
Prefer Generics When
- Multiple types share identical logic (sorting, filtering, map/reduce)
- You would otherwise rely on
anyand excessive type switching - You are building a reusable data structure (concurrent-safe set, ordered map)
Avoid Generics When
- Only one type is being instantiated in practice
- Interfaces already model the shared behavior cleanly
- The generic code is harder to read than the type-specific alternative
"Write code, don't design types." — Robert Griesemer and Ian Lance Taylor
Decision Flow
Do multiple types share identical logic?
├─ No → Use concrete types
├─ Yes → Do they share a useful interface?
│ ├─ Yes → Use an interface
│ └─ No → Use generics
Bad:
Details
- Repository
- github.com/cxuu/golang-skills
- Category
- Go
- First seen
- Jun 3, 2026
Questions
What does the go-generics skill help with in Go?
The go-generics skill guides you on whether to use Go generics, how to write generic functions and types, and how to choose constraints. It also covers picking between type aliases and type definitions. It applies even when you are writing a utility function that could work with multiple types without mentioning generics.
How do I install the go-generics skill?
Run npx -y skills add cxuu/golang-skills --skill go-generics -y in your project to install it. Once installed, the agent can decide when generics fit your code and avoid premature generics that only ever run with one type.
Which Go category does go-generics belong to, and what sets it apart there?
The go-generics skill sits in the Go category on Claude Marketplaces, where it ranks in the top 100. Its own guidance focuses on generics specifically, including when to avoid them, how to compose constraints with tilde and union operators, and common pitfalls such as over-constraining.
Does go-generics cover interface design?
It does not cover interface design without generics. For that topic, the skill points to go-interfaces, which handles the cases where an interface already models shared behavior cleanly.
What does the go-generics skill need to run?
The skill targets Go 1.18 or later, since generics require that version. The cmp package from Go 1.21 is referenced for standard constraints such as cmp.Ordered, but older versions can still use generics with the constraints package.
More from cxuu/golang-skills
All 20- Go Functions1.1K
- Go Declarations1.1K
- Go Code Review1.9K
- Go Testing1.5K
- Go Error Handling1.4K
- Go Concurrency1.4K
- Go Interfaces1.4K
- Go Linting1.4K
- Go Style Core1.4K
- Go Documentation1.4K
- Go Context1.4K
- Go Performance1.4K
- Go Naming1.4K
- Go Defensive1.4K
- Go Packages1.3K
- Go Functional Options1.3K
- Go Data Structures1.3K
- Go Control Flow1.3K
- Go Logging1.2K
Similar to Go Generics
More Gogo-interfacesSkillcxuu/golang-skills1.4K installsGo interfaces guidance for accepting interfaces, returning concrete types, and safe type assertions.
go-declarationsSkillcxuu/golang-skills1.1K installsGo declaration style guide covering var vs :=, iota enums, scope, struct and map initialization, and literal formatting.
golang-structs-interfacesSkillsamber/cc-skills-golang42.6K installsGo struct and interface design guide covering composition, embedding, type assertions, and pointer vs value receivers.
128-java-genericsPluginjabrena/plinth467 starsUse when you need to review, improve, or refactor Java code for generics quality — including avoiding raw types, applying the PECS (Producer Extends Consumer Su
golang-design-patternsSkillsamber/cc-skills-golang45.3K installsIdiomatic Go design patterns covering constructors, error flow, lifecycle, and architecture choices for production code.
typescript-advanced-typesSkillwshobson/agents103.4K installsComprehensive guide to TypeScript's advanced type system for building reusable, compile-time-safe type logic.