[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M79ZX88WQQFDHF4BKF1TQP91":3,"skill-same:01M79ZX88WQQFDHF4BKF1TQP91":52},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":24,"commitSha":25,"skillDirectory":26,"forksCount":14,"repositoryHtmlUrl":27,"repositoryHomepageUrl":6,"ownerHtmlUrl":28,"ownerBlogUrl":29,"ownerDescription":30,"updatedAt":31,"install":32,"resources":45},"01M79ZX88WQQFDHF4BKF1TQP91","go-generics",null,"Use when deciding whether to use Go generics, writing generic functions or types, choosing constraints, or picking between type aliases and type definitions. Also use when a user is writing a utility function that could work with multiple types, even if they don't mention generics explicitly. Does not cover interface design without generics (see go-interfaces).","kongnakornna\u002Fgolangapi","kongnakornna","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F10528904?v=4","01M79Z5JQPPV5CWQHXS235Q9MD","Kongnakorn Jantakun","01M79Z5JRHJJJ6PR2DGQS4P985",0,"Apache-2.0","https:\u002F\u002Fgithub.com\u002Fkongnakornna\u002Fgolangapi\u002Fblob\u002Fmain\u002F.github\u002Fskills\u002Fgolang-skills\u002Fskills\u002Fgo-generics\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: go-generics\ndescription: Use when deciding whether to use Go generics, writing generic functions or types, choosing constraints, or picking between type aliases and type definitions. Also use when a user is writing a utility function that could work with multiple types, even if they don't mention generics explicitly. Does not cover interface design without generics (see go-interfaces).\n---\n\n# Go Generics and Type Parameters\n\n> Compatibility: Generics require Go 1.18+.\n\n## Resource Routing\n\n- `references\u002FCONSTRAINTS.md` - Read when composing constraints, using type sets, or choosing between generics and interfaces.\n\n## When to Use Generics\n\nStart with concrete types. Generalize only when a second type appears.\n\n### Prefer Generics When\n\n- Multiple types share identical logic (sorting, filtering, map\u002Freduce)\n- You would otherwise rely on `any` and excessive type switching\n- You are building a reusable data structure (concurrent-safe set, ordered map)\n\n### Avoid Generics When\n\n- Only one type is being instantiated in practice\n- Interfaces already model the shared behavior cleanly\n- The generic code is harder to read than the type-specific alternative\n\n> \"Write code, don't design types.\" — Robert Griesemer and Ian Lance Taylor\n\n### Decision Flow\n\n```\nDo multiple types share identical logic?\n├─ No  → Use concrete types\n├─ Yes → Do they share a useful interface?\n│        ├─ Yes → Use an interface\n│        └─ No  → Use generics\n```\n\n**Bad:**\n\n```go\n\u002F\u002F Premature generics: only ever called with int\nfunc Sum[T constraints.Integer | constraints.Float](vals []T) T {\n    var total T\n    for _, v := range vals {\n        total += v\n    }\n    return total\n}\n```\n\n**Good:**\n\n```go\nfunc SumInts(vals []int) int {\n    var total int\n    for _, v := range vals {\n        total += v\n    }\n    return total\n}\n```\n\n---\n\n## Type Parameter Naming\n\n| Name | Typical Use |\n|------|-------------|\n| `T` | General type parameter |\n| `K` | Map key type |\n| `V` | Map value type |\n| `E` | Element\u002Fitem type |\n\nFor complex constraints, a short descriptive name is acceptable:\n\n```go\nfunc Marshal[Opts encoding.MarshalOptions](v any, opts Opts) ([]byte, error)\n```\n\n---\n\n## Type Aliases vs Type Definitions\n\nType aliases (`type Old = new.Name`) are rare — use only for package migration\nor gradual API refactoring.\n\n---\n\n## Constraint Composition\n\nCombine constraints with `~` (underlying type) and `|` (union):\n\n```go\ntype Numeric interface {\n    ~int | ~int8 | ~int16 | ~int32 | ~int64 |\n    ~float32 | ~float64\n}\n\nfunc Sum[T Numeric](vals []T) T {\n    var total T\n    for _, v := range vals {\n        total += v\n    }\n    return total\n}\n```\n\nUse the `constraints` package or `cmp` package (Go 1.21+) for standard constraints\nlike `cmp.Ordered` instead of writing your own.\n\n---\n\n## Common Pitfalls\n\n### Don't Wrap Standard Library Types\n\n```go\n\u002F\u002F Bad: generic wrapper adds complexity without value\ntype Set[T comparable] struct {\n    m map[T]struct{}\n}\n\n\u002F\u002F Better: use map[T]struct{} directly when the usage is simple\nseen := map[string]struct{}{}\n```\n\nGenerics justify their complexity when they eliminate duplication across\n**multiple call sites**. A single-use generic is just indirection.\n\n### Don't Use Generics for Interface Satisfaction\n\n```go\n\u002F\u002F Bad: T is only used to satisfy an interface — just use the interface\nfunc Process[T io.Reader](r T) error { ... }\n\n\u002F\u002F Good: accept the interface directly\nfunc Process(r io.Reader) error { ... }\n```\n\n### Avoid Over-Constraining\n\n```go\n\u002F\u002F Bad: constraint is more restrictive than needed\nfunc Contains[T interface{ ~int | ~string }](slice []T, target T) bool { ... }\n\n\u002F\u002F Good: comparable is sufficient\nfunc Contains[T comparable](slice []T, target T) bool { ... }\n```\n\n---\n\n## Quick Reference\n\n| Topic | Guidance |\n|-------|----------|\n| When to use generics | Only when multiple types share identical logic and interfaces don't suffice |\n| Starting point | Write concrete code first; generalize later |\n| Naming | Single uppercase letter (`T`, `K`, `V`, `E`) |\n| Type aliases | Same type, alternate name; use only for migration |\n| Constraint composition | Use `~` for underlying types, `|` for unions; prefer `cmp.Ordered` over custom |\n| Common pitfall | Don't genericize single-use code or when interfaces suffice |\n\n---\n\n## Related Skills\n\n- **Interfaces vs generics**: See [go-interfaces](..\u002Fgo-interfaces\u002FSKILL.md) when deciding whether an interface already models the shared behavior without generics\n- **Type declarations**: See [go-declarations](..\u002Fgo-declarations\u002FSKILL.md) when defining new types, type aliases, or choosing between type definitions and aliases\n- **Documenting generic APIs**: See [go-documentation](..\u002Fgo-documentation\u002FSKILL.md) when writing doc comments and runnable examples for generic functions\n- **Naming type parameters**: See [go-naming](..\u002Fgo-naming\u002FSKILL.md) when choosing names for type parameters or constraint interfaces\n","# Go Generics and Type Parameters\n\n> Compatibility: Generics require Go 1.18+.\n\n## Resource Routing\n\n- `references\u002FCONSTRAINTS.md` - Read when composing constraints, using type sets, or choosing between generics and interfaces.\n\n## When to Use Generics\n\nStart with concrete types. Generalize only when a second type appears.\n\n### Prefer Generics When\n\n- Multiple types share identical logic (sorting, filtering, map\u002Freduce)\n- You would otherwise rely on `any` and excessive type switching\n- You are building a reusable data structure (concurrent-safe set, ordered map)\n\n### Avoid Generics When\n\n- Only one type is being instantiated in practice\n- Interfaces already model the shared behavior cleanly\n- The generic code is harder to read than the type-specific alternative\n\n> \"Write code, don't design types.\" — Robert Griesemer and Ian Lance Taylor\n\n### Decision Flow\n\n```\nDo multiple types share identical logic?\n├─ No  → Use concrete types\n├─ Yes → Do they share a useful interface?\n│        ├─ Yes → Use an interface\n│        └─ No  → Use generics\n```\n\n**Bad:**\n\n```go\n\u002F\u002F Premature generics: only ever called with int\nfunc Sum[T constraints.Integer | constraints.Float](vals []T) T {\n    var total T\n    for _, v := range vals {\n        total += v\n    }\n    return total\n}\n```\n\n**Good:**\n\n```go\nfunc SumInts(vals []int) int {\n    var total int\n    for _, v := range vals {\n        total += v\n    }\n    return total\n}\n```\n\n---\n\n## Type Parameter Naming\n\n| Name | Typical Use |\n|------|-------------|\n| `T` | General type parameter |\n| `K` | Map key type |\n| `V` | Map value type |\n| `E` | Element\u002Fitem type |\n\nFor complex constraints, a short descriptive name is acceptable:\n\n```go\nfunc Marshal[Opts encoding.MarshalOptions](v any, opts Opts) ([]byte, error)\n```\n\n---\n\n## Type Aliases vs Type Definitions\n\nType aliases (`type Old = new.Name`) are rare — use only for package migration\nor gradual API refactoring.\n\n---\n\n## Constraint Composition\n\nCombine constraints with `~` (underlying type) and `|` (union):\n\n```go\ntype Numeric interface {\n    ~int | ~int8 | ~int16 | ~int32 | ~int64 |\n    ~float32 | ~float64\n}\n\nfunc Sum[T Numeric](vals []T) T {\n    var total T\n    for _, v := range vals {\n        total += v\n    }\n    return total\n}\n```\n\nUse the `constraints` package or `cmp` package (Go 1.21+) for standard constraints\nlike `cmp.Ordered` instead of writing your own.\n\n---\n\n## Common Pitfalls\n\n### Don't Wrap Standard Library Types\n\n```go\n\u002F\u002F Bad: generic wrapper adds complexity without value\ntype Set[T comparable] struct {\n    m map[T]struct{}\n}\n\n\u002F\u002F Better: use map[T]struct{} directly when the usage is simple\nseen := map[string]struct{}{}\n```\n\nGenerics justify their complexity when they eliminate duplication across\n**multiple call sites**. A single-use generic is just indirection.\n\n### Don't Use Generics for Interface Satisfaction\n\n```go\n\u002F\u002F Bad: T is only used to satisfy an interface — just use the interface\nfunc Process[T io.Reader](r T) error { ... }\n\n\u002F\u002F Good: accept the interface directly\nfunc Process(r io.Reader) error { ... }\n```\n\n### Avoid Over-Constraining\n\n```go\n\u002F\u002F Bad: constraint is more restrictive than needed\nfunc Contains[T interface{ ~int | ~string }](slice []T, target T) bool { ... }\n\n\u002F\u002F Good: comparable is sufficient\nfunc Contains[T comparable](slice []T, target T) bool { ... }\n```\n\n---\n\n## Quick Reference\n\n| Topic | Guidance |\n|-------|----------|\n| When to use generics | Only when multiple types share identical logic and interfaces don't suffice |\n| Starting point | Write concrete code first; generalize later |\n| Naming | Single uppercase letter (`T`, `K`, `V`, `E`) |\n| Type aliases | Same type, alternate name; use only for migration |\n| Constraint composition | Use `~` for underlying types, `|` for unions; prefer `cmp.Ordered` over custom |\n| Common pitfall | Don't genericize single-use code or when interfaces suffice |\n\n---\n\n## Related Skills\n\n- **Interfaces vs generics**: See [go-interfaces](..\u002Fgo-interfaces\u002FSKILL.md) when deciding whether an interface already models the shared behavior without generics\n- **Type declarations**: See [go-declarations](..\u002Fgo-declarations\u002FSKILL.md) when defining new types, type aliases, or choosing between type definitions and aliases\n- **Documenting generic APIs**: See [go-documentation](..\u002Fgo-documentation\u002FSKILL.md) when writing doc comments and runnable examples for generic functions\n- **Naming type parameters**: See [go-naming](..\u002Fgo-naming\u002FSKILL.md) when choosing names for type parameters or constraint interfaces\n",{"name":5,"description":7},"main","19f4d52a98d557f3a645a2cfbbeb5bd54f28831d",".github\u002Fskills\u002Fgolang-skills\u002Fskills\u002Fgo-generics","https:\u002F\u002Fgithub.com\u002Fkongnakornna\u002Fgolangapi","https:\u002F\u002Fgithub.com\u002Fkongnakornna","http:\u002F\u002Fcmoniot.trueddns.com:52160","Technical Skills and Expertise\r\nLanguages and Frameworks\r\nFrontend: HTML, JavaScript, TypeScript, React, Vue, Angular, Next.js\r\nBackend: Node.js,Python,Golang","2026-10-06 23:01:46",{"source":8,"skillName":5,"commands":33,"prompt":43,"zipAvailable":44},[34,37,40],{"tool":35,"command":36},"npx","npx skills add kongnakornna\u002Fgolangapi --skill go-generics",{"tool":38,"command":39},"bunx","bunx skills add kongnakornna\u002Fgolangapi --skill go-generics",{"tool":41,"command":42},"pnpm","pnpm dlx skills add kongnakornna\u002Fgolangapi --skill go-generics","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fkongnakornna\u002Fgolangapi\u002Fblob\u002Fmain\u002F.github\u002Fskills\u002Fgolang-skills\u002Fskills\u002Fgo-generics\u002FSKILL.md",true,[46],{"path":47,"resourceType":48,"resourceTypeDesc":49,"sizeBytes":50,"sourceHtmlUrl":51},"references\u002FCONSTRAINTS.md","REFERENCE","参考文档",4756,"https:\u002F\u002Fgithub.com\u002Fkongnakornna\u002Fgolangapi\u002Fblob\u002Fmain\u002F.github\u002Fskills\u002Fgolang-skills\u002Fskills\u002Fgo-generics\u002Freferences\u002FCONSTRAINTS.md",[53,60,67,74,81,88],{"skillNo":54,"name":55,"nameZh":6,"description":56,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":57,"categories":58,"keywords":59,"publishedAt":19},"01M7A0M9RJJ3383VEFYKABWV15","tb-writing-plans","Use when you have a spec or requirements for a multi-step task, before touching code","https:\u002F\u002Fgithub.com\u002Fkongnakornna\u002Fgolangapi\u002Fblob\u002Fmain\u002F.github\u002Fskills\u002Ftb-writing-plans\u002FSKILL.md",[],[],{"skillNo":61,"name":62,"nameZh":6,"description":63,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":64,"categories":65,"keywords":66,"publishedAt":19},"01M7A0M4JKY4DEDRP1CBHT00WV","tb-using-git-worktrees","Use when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallback","https:\u002F\u002Fgithub.com\u002Fkongnakornna\u002Fgolangapi\u002Fblob\u002Fmain\u002F.github\u002Fskills\u002Ftb-using-git-worktrees\u002FSKILL.md",[],[],{"skillNo":68,"name":69,"nameZh":6,"description":70,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":71,"categories":72,"keywords":73,"publishedAt":19},"01M7A0KZ5HRAQAAT2KXR6146Q7","tb-test-driven-development","Use when implementing any feature or bugfix, before writing implementation code","https:\u002F\u002Fgithub.com\u002Fkongnakornna\u002Fgolangapi\u002Fblob\u002Fmain\u002F.github\u002Fskills\u002Ftb-test-driven-development\u002FSKILL.md",[],[],{"skillNo":75,"name":76,"nameZh":6,"description":77,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":78,"categories":79,"keywords":80,"publishedAt":19},"01M7A0KW92W3F18E2MRP8H62P2","tb-subagent-driven-development","Use when executing implementation plans with independent tasks in the current session","https:\u002F\u002Fgithub.com\u002Fkongnakornna\u002Fgolangapi\u002Fblob\u002Fmain\u002F.github\u002Fskills\u002Ftb-subagent-driven-development\u002FSKILL.md",[],[],{"skillNo":82,"name":83,"nameZh":6,"description":84,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":85,"categories":86,"keywords":87,"publishedAt":19},"01M7A0KKYQCHYYRHA5J5BAP24M","tb-scrutinize","Outsider-perspective end-to-end review of a plan, PR, or code change. First questions intent and whether a simpler\u002Fmore elegant approach would achieve the same goal, then traces the actual code path (not just the diff) to verify the change does what it claims. Output is concise, actionable, and every call carries its rationale. Trigger on \u002Ftb-scrutinize and proactively whenever the user asks to review, audit, sanity-check, or get a second opinion on a plan, PR, diff, design doc, or proposed code change.","https:\u002F\u002Fgithub.com\u002Fkongnakornna\u002Fgolangapi\u002Fblob\u002Fmain\u002F.github\u002Fskills\u002Ftb-scrutinize\u002FSKILL.md",[],[],{"skillNo":89,"name":90,"nameZh":6,"description":91,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":92,"categories":93,"keywords":94,"publishedAt":19},"01M7A0KFDR1V3RW7SW1XNHP82P","tb-requesting-code-review","Use when completing tasks, implementing major features, or before merging to verify work meets requirements","https:\u002F\u002Fgithub.com\u002Fkongnakornna\u002Fgolangapi\u002Fblob\u002Fmain\u002F.github\u002Fskills\u002Ftb-requesting-code-review\u002FSKILL.md",[],[]]