Unions of type sets
May 1, 2023
General interfaces
…
Union elements denote unions of type sets:
// The Float interface represents all floating-point types // (including any named types whose underlying types are // either float32 or float64). type Float interface { ~float32 | ~float64 }
Here we see our first example of a union of type sets. The example shows an interface of all types with an underlying float
type. The equivalent for integer types is a bit longer, due to the large number of distinct integer types in Go, but would look like:
type Int interface {
~uint8 | ~uint16 | ~uint32 | ~uint64 | ~int8 | ~int16 | ~int32 | ~int64
}
Quotes from The Go Programming Language Specification Version of December 15, 2022