Thanks, kortschak!

I still need some time to understand the proposal in 
https://github.com/golang/go/issues/51338, but I think the code provided in 
the Go Playground is exactly what I want!

On Friday, March 18, 2022 at 4:13:22 PM UTC+8 kortschak wrote:

> 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/e06b53f6-2d89-44ae-a320-0f371b6dc855n%40googlegroups.com.

Reply via email to