I'm trying to find a comparable-like interface that I can use in the following code:
func SliceMax[T comparable](ts []T) (T, error) {
if len(ts) == 0 {
return 0, errors.New("cannot get max from empty slice")
}
m := ts[0]
for _, e := range ts {
if e > m {
m = e
}
}
return m, nil
}
But comparable doesn't work (it fails on the > sign). Is there a built in interface here or do I need to write my own?