MCPcopy Index your code
hub / github.com/derekbanas/Go-Tutorial / MyConstraint

Interface MyConstraint

hellogo.go:114–116  ·  view source on GitHub ↗

----- FUNCTION THAT EXCEPTS GENERICS ----- This generic type parameter is capital, between square brackets and has a rule for what data it will except called a constraint any : anything comparable : Anything that supports == More Constraints : pkg.go.dev/golang.org/x/exp/constraints You can also def

Source from the content-addressed store, hash-verified

112// You can also define what is excepted like this
113// Define that my generic must be an int or float64
114type MyConstraint interface {
115 int | float64
116}
117
118func getSumGen[T MyConstraint](x T, y T) T {
119 return x + y

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected