Re:New in Go 1.20: wrapping multiple errors
by p-e-w on Sunday December 11, 2022 @08:32AM
(#33942994)
Because they can't be properly implemented without generics, and generics were only shoehorned into Go a decade after its initial release.
[ Parent
| on HN ]
Re:New in Go 1.20: wrapping multiple errors
by masklinn on Sunday December 11, 2022 @09:04AM
(#33943259)
They could be implemented as builtins, like channels, slices, and maps were.
Though what's really missing is generic set functions, and a decision as to which "hashmap shape" is the blessed set (between map[T]struct{} and map[T]bool), a "set" builtin can just be an alias to that in the same way "any" is an alias for "interface{}".
Re:New in Go 1.20: wrapping multiple errors
by kasey_junk on Sunday December 11, 2022 @08:50AM
(#33943149)
The go language has had generics since inception, just not user defined ones.
If they wanted a set data structure they could have had it like they do maps and slices.
Re:New in Go 1.20: wrapping multiple errors
by XorNot on Sunday December 11, 2022 @09:05AM
(#33943263)
Set is just a Map though where you don't care about the values.
var m[string]struct{} implements this for you.
What you're really missing is the usual suite of helper methods which make sets ergonomic - and for that you need proper generics.
Re:New in Go 1.20: wrapping multiple errors
by masklinn on Monday December 12, 2022 @02:47AM
(#33952039)
Fwiw lots of folks dislike m[K]struct{}, because while it’s efficient checking for presence is horrible:
_, present = m[k]
It looks weird and is not an expressions. Obviously you could paper over this with a dedicated builtin function but that’s not great.A common alternative is m[string]bool, memory density is worse but contains/add/remove are easier to read and more convenient.