The generics tutorial uses this:
type Number interface {
int64 | float64
}
Is there no interface for all integer and float types in golang?
The generics tutorial uses this:
type Number interface {
int64 | float64
}
Is there no interface for all integer and float types in golang?
You can declare a new type constraint which integrates constraints.Float
and constraints.Integer
.
// Number is a custom type set of constraints extending the Float and Integer type set from the experimental constraints package.
type Number interface {
constraints.Float | constraints.Integer
}