News for hackers. Stuff that matters.
Re:What I'd like to see in Go 2.0 by lucian1900 on Friday February 04, 2022 @07:52AM (#30206169)
Or even better, proper sum types. They're a superset of enums anyway.

https://github.com/BurntSushi/go-sumtype is great, but a bit unwieldy. Language support would be much better.

Re:What I'd like to see in Go 2.0 by catlifeonmars on Friday February 04, 2022 @02:46PM (#30211947)
Proper compile time sum types would be great. I find myself reimplementing sum types at runtime far too often, especially when it comes to parsing JSON. My go to is a function with a signature along the lines of the reflect packages dynamic select:

func UnmarshalOneOf(data []byte, args []interface{}) (index int, err error)

Which I use like this:

variants := []interface{}{ &T1{}, &T2{}}

i, err := UnmarshalOneOf(data, variants)

// …

return variants[i]