A custom constraint interface can use the union operator | to permit alternative type terms. For example, ~int | ~string accepts types whose underlying type is int or string, rather than every comparable type. The union narrows which type arguments a generic function may receive. section 2.9.1
Restricting a generic map helper
Define customConstraint with ~int | ~string, then use it as the key parameter constraint for getKeys. A map[string]int is accepted, and Go can infer string as the type argument. Replacing the union with int or string changes whether named types with those underlying types are admitted. section 2.9.1
type customConstraint interface {
~int | ~string #1
}
func getKeys[K customConstraint, #2
V any](m map[K]V) []K {
// Same implementation
}
Shows the union constraint and its placement on the generic getKeys function. section 2.9.1

