|
|
|
|
|
by sidlls
1302 days ago
|
|
Generics as currently implemented in go are so limited that you may as well stick with interfaces for anything but trivial boilerplate or textbook data structure/algorithm implementations. For example, it's currently impossible to define type constraints with user-defined interfaces embedded: ```
// this is legal
type MyConstraint interface {
int64 | float
}
type SomeAPI interface {
AMethod() error
}
// Nope
type CantHaveThisConstraint interface {
int64 | float | SomeAPI
}
// NOPE
func SomeGeneric[T CantHaveThisConstraint](...) {
}
```
|
|