Skip to content

Instantly share code, notes, and snippets.

@sausheong
Created May 16, 2022 05:40
Show Gist options
  • Save sausheong/567c028d9e184585ad487f5c8610815b to your computer and use it in GitHub Desktop.
Save sausheong/567c028d9e184585ad487f5c8610815b to your computer and use it in GitHub Desktop.
generics
import "golang.org/x/exp/constraints"
type Number interface {
constraints.Integer | constraints.Float
}
func AddNumbers[T Number](a, b T) T {
return a + b
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment