[go-nuts] Re: slog.GroupValue could potentially not make a new slice

2023-08-14 Thread Diego Augusto Molina
:]) // no need to keep a reference to the string Key as = as[:write] return Value{num: uint64(len(as)), any: groupptr(unsage.SliceData(as))} } On Monday, 14 August 2023 at 22:06:57 UTC-3 Diego Augusto Molina wrote: > Hello everyone, thank you for reading. I'm looking at the c

[go-nuts] slog.GroupValue could potentially not make a new slice

2023-08-14 Thread Diego Augusto Molina
Hello everyone, thank you for reading. I'm looking at the code of slog.GroupValue (https://cs.opensource.google/go/go/+/refs/tags/go1.21.0:src/log/slog/value.go;l=171) and was wondering if we could benefit from reusing the same slice like this: // GroupValue returns a new Value for a list of

Re: [go-nuts] Generic zero value for compiler optimization

2023-08-14 Thread Diego Augusto Molina
Thank you very much, that's actually what I was looking for. On Monday, 14 August 2023 at 13:57:35 UTC-3 Axel Wagner wrote: > You might be interested in https://github.com/golang/go/issues/61372 > > On Mon, Aug 14, 2023 at 3:52 PM Diego Augusto Molina < > diegoaugu...@gmail.com&

[go-nuts] Generic zero value for compiler optimization

2023-08-14 Thread Diego Augusto Molina
Hi, thank you for reading. Whenever I need to use a zero value for a generic type in a func I do something like the following: func SetZero[T any](pt *T) T { var zeroT T *pt = zeroT } That's all good, but I wonder how, if possible, it could be proved to the compiler that zeroT is the

[go-nuts] Re: Safely implementing Is(target error) bool

2023-07-31 Thread Diego Augusto Molina
nelErr == target" it had done something like "errors.Is(target, sentinelErr)". This is evidently an internal issue, not with the standard library, sorry about the fuzz. On Monday, 31 July 2023 at 17:22:11 UTC-3 Diego Augusto Molina wrote: > Hello everyone. In relation to standa

[go-nuts] Safely implementing Is(target error) bool

2023-07-31 Thread Diego Augusto Molina
Hello everyone. In relation to standard errors package, I wanted to ask about safe ways of implementing Is(target error) bool. The current documentation (https://cs.opensource.google/go/go/+/refs/tags/go1.20.6:src/errors/wrap.go;l=35) says the following: // An error type might provide an Is

[go-nuts] Upgradable RLock

2023-01-29 Thread Diego Augusto Molina
>From times to times I write a scraper or some other tool that would authenticate to a service and then use the auth result to do stuff concurrently. But when auth expires, I need to synchronize all my goroutines and have a single one do the re-auth process, check the status, etc. and then

[go-nuts] [generics] Typo in draft

2020-06-28 Thread Diego Augusto Molina
Hi, I think I spotted a small typo in the draft. In Examples > Containers we have: // Find returns the value associated with a key, or zero if not present. // The bool result reports whether the key was found. func (m *Map(K, V)) Find(k K) (V, bool) { pn := m.find(k) if *pn == nil

[go-nuts] Add string Parser to x/tools/stringer

2020-06-07 Thread Diego Augusto Molina
Very often I use the stringer command to generate lists of enumerated values, which is great btw. But one thing that I see myself also writing after this is a Parse method or function to validate strings that are received. The use case is that I have a list of possible values for a controlled