[go-nuts] Generic type for struct method: constraint problem && cannot use (untyped string constant) as string value

2023-11-09 Thread ahuigo
There is an example: https://go.dev/play/p/guzOWRKi-yp ``` func (c *cachedFn[string, V]) Get0() (V, error) { // var s any var s string s = "abc" // error: cannot use "abc" (untyped string constant) as string value in assignment fmt.Printf("cache key: %#v, %T\n", s, s) // cache key: 0, uint8 retur

Re: [go-nuts] Generic type for struct method: constraint problem && cannot use (untyped string constant) as string value

2023-11-09 Thread ahuigo
t;cache key: %#v, %T\n", s, s) // cache key: 0, uint8 return c.Get(s) } On Friday, November 10, 2023 at 4:34:46 AM UTC+8 Axel Wagner wrote: > Yes, this has come up before. > > On Fri, Nov 10, 2023 at 7:09 AM ahuigo wrote: > >> There is an example: https://go.dev/play/p

[go-nuts] Re: I think in Golang, Array, Slice, and Map , all of them are very difficult to use。

2023-11-09 Thread ahuigo
Instead of reflect library. I'd like to recommend this generic library https://github.com/samber/lo. It's very convenient than reflect, and I've been using it for a long time. If you are not familiar about how to use it, ask GPT4(GPT3.5 does't know it) On Friday, June 20, 2014 at 4:47:38 PM UTC+