On Thu, 2022-03-17 at 18:47 -0700, RussellLuo wrote: > Is there any way to write a constraint, say, SliceOrMap, to support > either a slice or a map? > > With the help of SliceOrMap, then I can write a more generic version > `LenBetween` like this: > > ```go > func MapLenBetween[T SliceOrMap](s T, min, max int) bool { > return len(s) >= min && len(s) <= max > } > ```
Not yet AFAICS, but see https://github.com/golang/go/issues/51338. If something like that is adopted, then you could write https://go.dev/play/p/4RyDr_u1WAM. -- 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/5e35af34528d0490243dd64e5110c7f600587eb6.camel%40kortschak.io.