What's coming in Go 1.18
What's coming in Go 1.18
Posted Feb 9, 2022 8:45 UTC (Wed) by taladar (subscriber, #68407)Parent article: What's coming in Go 1.18
> func min(x float32, y float32) float32 {
> if x < y {
> return x
> }
> return y
> }
> if x < y {
> return x
> }
> return y
> }
> type ordered interface {
> float32 | float64 | int
> }
> func min[T ordered](x T, y T) T {
> if x < y {
> return x
> }
> return y
> }
That looks like it is significantly less expressive than proper generics with open traits/type classes/interfaces/...
Can you really only specify a closed, one-time list without being able to add new types to it later?
