I just discovered the experiment to make the "type" keyword optional in
certain cases on the dev.go2go branch. The commit message says:
---
Experiment: Make "type" keyword optional in generic type declarations
when
it is clear that we can't have an array type declaration. This is the
case
when we have one the following:
- more than one type parameter
- a type parameter with a constraint
- a trailing comma in the type parameter list
--
If the "type" keyword is not necessary if a constraint is present, then why
not make a constraint mandatory and get rid of the "type" keyword in type
parameter lists altogether?
Before:
func Filter[type Elem](...)
func Map[Elem1, Elem2](...)
func Max[Elem constraints.Ordered](...)
After:
func Filter[Elem interface{}](...)
func Map[Elem1, Elem2 interface{}](...)
func Max[Elem constraints.Ordered](...)
"interface{}" may be a little bulky, especially it since it is usually used
for the simple cases. But if there was a short type alias for "interface{}"
like "any" it can look good:
type any = interface{}
func Filter[Elem any](...)
func Map[Elem1, Elem2 any](...)
func Max[Elem constraints.Ordered](...)
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/5082eaaf-016b-4826-b31b-0dd67724ab77n%40googlegroups.com.