---
title: Go generics and the operations a constraint permits
slug: go-generics
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source: https://iinventedlight.com/library/notes/go-generics.md
source_license: CC-BY-4.0
attribution: Original synthesis by iinventedlight, drafted by Librarian with AI assistance; based on the attributed sources
  below.
author: Librarian
client: Librarian
date: '2026-11-05'
checked_on: '2026-11-05'
as_of: '2026-11-05'
status: published
confidence: medium
category: coding-references
tags:
- go
- generics
untested: Reference note. No code or commands were run to validate behavior.
sources:
- id: S1
  title: Getting started with generics
  publisher: The Go Authors
  url: https://go.dev/doc/tutorial/generics
  accessed: '2026-11-05'
  license: CC-BY-4.0
  license_url: https://go.dev/doc/copyright
  license_verified: '2026-11-05'
  green: true
  attribution: The Go Authors; Getting started with generics; CC-BY-4.0
  snapshot: _fetched/go-generics.txt
- id: S2
  title: An introduction to generics
  publisher: The Go Authors
  url: https://go.dev/blog/intro-generics
  accessed: '2026-11-05'
  license: CC-BY-4.0
  license_url: https://go.dev/doc/copyright
  license_verified: '2026-11-05'
  green: true
  attribution: The Go Authors; An introduction to generics; CC-BY-4.0
  snapshot: _fetched/go-intro.txt
---
# Go generics and the operations a constraint permits

## Summary
Go type parameters let one function or type accept a specified set of types. A constraint limits the permitted type arguments and the operations available inside the generic definition. [S1, S2]

## Details
A generic body must work for every type admitted by its constraints. The Go tutorial uses `comparable` for a map key and a union of numeric types for values. The compiler can often infer type arguments from ordinary function arguments, so callers need not always write them explicitly. [S1, S2]

## Claims
- id: C1
  claim: "A type constraint defines which type arguments a caller may supply."
  source: S1
  evidence: "Each type constraint specifies the permissible type"
- id: C2
  claim: "An operation in generic code must be supported by the constraint."
  source: S1
  evidence: "a type parameter must support all the operations"
- id: C3
  claim: "Inference can let a function call omit explicit type arguments."
  source: S2
  evidence: "Type inference, which permits omitting type arguments"

## Sources
- [S1] Getting started with generics. The Go Authors. https://go.dev/doc/tutorial/generics. CC-BY-4.0; license: https://go.dev/doc/copyright. Accessed 2026-11-05.
- [S2] An introduction to generics. The Go Authors. https://go.dev/blog/intro-generics. CC-BY-4.0; license: https://go.dev/doc/copyright. Accessed 2026-11-05.

## Attribution and notices
This note is CC BY 4.0. Source material has been condensed and restated; short evidence excerpts retain their source license.

Go documentation text is CC BY 4.0; code is BSD-licensed. No source code is reproduced.
