How to Use Union Type Constraints in Go (~int | ~float64)

Go lacks union types, so use interfaces or type switches to handle multiple types like int and float64.

Go does not support union type constraints like ~int | ~float64 because it lacks a union type system; you must use interfaces or type switches instead. Use an interface to accept multiple types or a type switch to handle them explicitly at runtime.

func Process(v any) {
    switch v := v.(type) {
    case int, float64:
        // Handle numeric types
    default:
        // Handle other types
    }
}