✳flâneur — a map of the web's best reading
Getting started with Golang Generics | GoLinuxCloud
golinuxcloud.com · 1,851 words · saved by 1 readers
We end this section by stating some useful facts about golang generics:
Golang Generics Generic Syntax Explained (T any, Constraints) go Copy func Print [ T any ]( v T ) {} func Sum [ T int | float64 ]( a , b T ) T {} T → type parameter any → allows any type Constraints → restrict allowed types Common Generic Patterns (Functions, Structs, Interfaces) go Copy // Generic function func Max [ T int | float64 ]( a , b T ) T { return a } // Generic struct type Box [ T any ] struct { value T } // Generic map helper func Keys [ K comparable , V any ]( m map [ K ] V ) [] K {} When to Use Generics (Quick Rules) Avoid duplicate functions for different types Use for reusable
Explore this link on the map →related reading
- Frequently Asked Questions (FAQ) - The Go Programming Languagego.dev
- Generic Data Types - The Rust Programming Languagedoc.rust-lang.org
- Generic Types, Traits, and Lifetimes - The Rust Programming Languagedoc.rust-lang.org
- TypeScript: Documentation - Genericstypescriptlang.org
- Go go-to guide · YourBasicyourbasic.org
- The Go Programming Language Specification - The Go Programming Languagego.dev
- Writing Better Go: Lessons from 10 Code Reviews - Speaker Deckspeakerdeck.com
- Writing Better Go: Lessons from 10 Code Reviews - Speaker Deckspeakerdeck.com
- Effective Go - The Go Programming Languagego.dev
- Notes on structured concurrency, or: Go statement considered harmful - njs blogvorpus.org
- Go at Google: Language Design in the Service of Software Engineering - The Go Programming Languagego.dev
- Go类型系统概述 -Go语言101gfw.go101.org