Re: [go-nuts] Maps with non-comparable keys

2021-12-23 Thread aind...@gmail.com
> I think it is unlikely to ever happen Yeah, it'd require a language change wouldn't it? Still, it'd be nice to take advantage of the runtime's map implementation without starting from scratch. > I tried my hand at it for fun Nice work! I like the use of map[uint64][]keyVal. -- You received

Re: [go-nuts] Maps with non-comparable keys

2021-12-23 Thread Kevin Chowski
I tried my hand at it for fun :) it is a linear probed hashmap based on uint64 map keys: https://gotipplay.golang.org/p/gzrbS-B6ixg I claim no rights nor responsibility for the above example; it only took me like 20 minutes and has extremely minimal testing; it may contain bugs. Use at your own

Re: [go-nuts] Maps with non-comparable keys

2021-12-23 Thread Ian Lance Taylor
On Thu, Dec 23, 2021 at 12:42 PM aind...@gmail.com wrote: > > Now that generics is coming along, is there an easy way to extend the builtin > map type to use a non-comparable key type? For example, given this constraint > > type Key[T any] interface { > Size() uint64 > Hash(seed u

Re: [go-nuts] Maps with non-comparable keys

2021-12-23 Thread 'Axel Wagner' via golang-nuts
It is not possible and I think it is unlikely to ever happen (though it might be reasonably implemented as a library at some point). On Thu, Dec 23, 2021 at 9:42 PM aind...@gmail.com wrote: > Now that generics is coming along, is there an easy way to extend the > builtin map type to use a non-co

[go-nuts] Maps with non-comparable keys

2021-12-23 Thread aind...@gmail.com
Now that generics is coming along, is there an easy way to extend the builtin map type to use a non-comparable key type? For example, given this constraint type Key[T any] interface { Size() uint64 Hash(seed uint64) uint64 Equal(T) bool } and a type Foo like type Foo []

[go-nuts] Re: Golang JSONObject

2021-12-23 Thread 'Soufien Benramdhane' via golang-nuts
Hi A JI, Here the documentation linked to json.Unmarshal : https://pkg.go.dev/encoding/json#Marshal It works only exported fields. Since your field *price* is unexported, Marshal would just ignore it. You should probably try this: https://go.dev/play/p/49Zm1fawC9F Using an intermediate anonym

[go-nuts] Re: Alternatives to wrapping errors

2021-12-23 Thread Kevin Chowski
Have you seen https://go.dev/blog/go1.13-errors? If one wants to use error unwrapping, these days generally it is suggested to use the functionality from the standard package "errors" (or fmt.Errorf) rather than some third-party package. That way everyone does it the same way, making third-part

[go-nuts] Re: Golang JSONObject

2021-12-23 Thread Kevin Chowski
This is not a real "why", but this how json.Marshal works according to the documentation. From https://pkg.go.dev/encoding/json#Marshal: "Struct values encode as JSON objects. Each exported struct field becomes a member of the object, using the field name as the object key, unless the field is

[go-nuts] Golang JSONObject

2021-12-23 Thread A JI
Why, when the object of struct is lowercase. I can't fill it and convert to JSON ? https://go.dev/play/p/WZCvC7M5YAp -- 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

[go-nuts] Re: beginner : best way to learn go

2021-12-23 Thread Ajith A
Best & effective way to learn go is the online courses. Now there are number of courses available in online, but not all of them are worth your time and money. Here are some tips to help you get started your digital learning. 1. go to Learn From Online

[go-nuts] Alternatives to wrapping errors

2021-12-23 Thread Jonathan Hall
I was recently catching up on the latest state of the github.com/pkg/errors package (https://github.com/pkg/errors/issues/245), when I noticed that Dave Cheney said: > I no longer use this package, in fact I no longer wrap errors. I'm curious what approach Dave uses now, but unless/until he wri