Hi Ian, all,

On Wed, Jan 18, 2023 at 6:56 PM Ian Lance Taylor <i...@golang.org> wrote:
> > // IsEmpty checks if the interface is equal to nil.
> > func IsEmpty[T Block](blk T) bool {
> >     var empty T
> >     return empty == blk
> > }
> >
> > (I had blk Block before, instead of blk T).
> >
> > Comparing with empty is something I've needed to do a bunch of times
> > and have been unable to do.
>
> The type argument to a function like IsEmpty is rarely an interface
> type.  So the comparison in the instantiation IsEmpty is not comparing
> values of interface type.  It's comparing values of whatever type
> IsEmpty is instantiated with.  And it is possible to instantiate
> IsEmpty with types that can't be compared, even with their zero value,
> such as [1][]byte.

This makes sense, however, is there any way to compare against empty
in this context? I was wondering how to go about doing that.

Thanks,
Christian

-- 
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/CA%2Bh8R2qyGdhrJ7%3DuCAJRN_SSruKDfxZ8zrV3mdgmN3x9_Rbh9Q%40mail.gmail.com.

Reply via email to