4 ms·
What about struct{}?
by RunOutOfMemory 5y ago
What about struct{}?
- ibraheemdev 5y agoWhat about it?
- RunOutOfMemory 5y agointerface{} -> any struct{} -> ?
- lalaithion 5y agoI suppose you could define a type alias "unit". It's not surprising to me that this isn't in the go standard library though.
- benhoyt 5y agoYou 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.
- ainar-g 5y agoWe 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.
- deleted 5y ago[deleted]