top | item 29561957

(no title)

RunOutOfMemory | 4 years ago

interface{} -> any

struct{} -> ?

discuss

order

lalaithion|4 years ago

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.

benhoyt|4 years ago

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.

ainar-g|4 years ago

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.