Function that takes values that fall in some category

If I want to create a function that takes a value of any type, I can use an empty interface.
For example,

	fmt.Printf("(%v, %T)\n", i, i)
}

But what should I do if, for example, I want to create a function that takes integers and floats only? Are there any built-in interfaces for built-in data types?

Not with current versions of Go, though once Gos generics are out, you should be able to put a constraint for that.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.