Same question for `len()`: is there a way to declare a constraint that matches types that support `len()` ?
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.