Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

interface{} -> any

struct{} -> ?



I suppose you could define a type alias "unit". It's not surprising to me that this isn't in the go standard library though.


You can define that yourself as "type token = struct{}" or similar. In my experience struct{} occurs even less than interface{}, and it's also 3 characters shorter already, so it's not worth a builtin. I use "chan struct{}" for synchronizing and sometimes use "map[string]struct{}" for sets.


We use the alias "unit", like lalaithion has said before, in many projects. It's a bit annoying to declare it in every package though. Hopefully, there'll be an official alias in the future.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: