On Thu, Dec 22, 2022 at 2:24 PM Pierre Durand <pierredur...@gmail.com>
wrote:

> Same question for `len()`: is there a way to declare a constraint that
> matches types that support `len()` ?


For this, the workaround you posted works, at least. It's not convenient,
but it also does not seem like a common need - again I'd be kind of curious
what you want it for.


>
> Le jeudi 22 décembre 2022 à 14:23:22 UTC+1, Pierre Durand a écrit :
>
>> Is there a way to declare a "nillable" constraint that matches all types
>> that can be nil (pointer, slice, map, etc.) ?
>>
>> I would like to write a function, that receives a parameter (with a
>> generic type), and check if this parameter is nil.
>> I found a very ugly way to write it: https://go.dev/play/p/0g0SoTlBEgs
>> The problem: the map type needs more than 1 type, so I need to provide
>> the 3 types when I call the `IsNil()` function/
>> Is there a better way ?
>>
>> Yes I know I could use `any`, and check with reflect if the value inside
>> the interface is nil.
>> But I want to know if it's possible to do it with generics.
>>
>> Thank you.
>>
> --
> 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/5101cdb3-601a-4eec-b278-5be07a891590n%40googlegroups.com
> <https://groups.google.com/d/msgid/golang-nuts/5101cdb3-601a-4eec-b278-5be07a891590n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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/CAEkBMfGKqXE5KNnCWW7T-1jqFJN6TF7JzV7_ZNvTKFARLegxRg%40mail.gmail.com.

Reply via email to