Back to course

Generics in Go (v1.18+)

Go (Golang) for Cloud-Native Microservices

Reusable Code with Generics

Generics allow you to write functions that work with multiple types without using reflection.

go func MapValues[K comparable, V any](m map[K]V) []V { var res []V for _, v := range m { res = append(res, v) } return res }

This is great for utility functions and data structures (stacks, queues).