On Wed, Jan 6, 2021 at 11:31 PM Amit Saha <amitsaha...@gmail.com> wrote:

> In the description of context.WithValue(), we have:
>
> The provided key must be comparable and should not be of type string
> or any other built-in type to avoid collisions between packages using
> context. Users of WithValue should define their own types for keys. To
> avoid allocating when assigning to an interface{}, context keys often
> have concrete type struct{}.
>
> I am wondering if someone can explain what exactly comparable means here?
>
> In other languages and Go
> (https://golang.org/ref/spec#Comparison_operators), comparable usually
> means being able to compare two values for equality/greater/lesser.
>

The linked spec section actually contradicts that:

The equality operators == and != apply to operands that are *comparable*.
> The ordering operators <, <=, >, and >= apply to operands that are
> *ordered*.


(emphasis from the spec). So, the definition of "comparable" is "can be
used with == and !=" and what exactly that means is listed below that quote.

Hope that helps


> Thanks,
> Amit.
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/CANODV3kUmtJvG9Lfys_HXfedwnm54neA6uub6cY1aiz%2B9w5DUA%40mail.gmail.com
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAEkBMfE2jqTT0QC7ykCEgVQPgB-%3DEyYfzz%3D2uDmTTwkMEFcB5Q%40mail.gmail.com.

Reply via email to