-
Notifications
You must be signed in to change notification settings - Fork 18k
proposal: maps: remove package for Go 1.21 #61613
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Just repeating myself from the other issue: We might want |
Could this be resolved by having a special naming convention for iterator variants of allocating functions? E.g. we could ship maps.Keys now, and add maps.KeysIter later? Edit: The reason for pulling maps.Keys was that it forces allocation, but returning an iterator imposes the opposite problem: what if I want a slice of keys? I'd have to allocate the slice, iterate through and build up the slice, etc. I'm not sure there's a right "default" approach here; both variants are useful. |
Building a slice from an iterator doesn't necessarily require any extra allocation: package iters
func Append[T any](s []T, iter Iter[T]) []T {
for v := range iter {
s = append(s, v)
}
return s
} Then you can just append the That being said, I do think that keys := iters.Append(make([]T, 0, len(m)), maps.Keys(m)) which is really kind of awkward. |
This comment was marked as off-topic.
This comment was marked as off-topic.
@AndrewHarrisSPU |
My initial reaction to this was this seemed a bit heavy handed, but the more I thought about it in relation to the One of the the things that I think, @ianlancetaylor say at one point is, it would be nice to define additional Would a the existing |
Pulling all of maps seems strictly more disruptive than pulling just Keys and Values. |
No change in consensus, so declined. |
#61538 removed maps.Keys and maps.Values from Go 1.21 pending #61405. However, a number of users suggested that Keys and Values are the most valuable pieces of package maps, and not having them available in the standard library can cause friction, especially with automatic import management in e.g. goimports and gopls.
This proposal is to hold back the entire package instead of only Keys and Values. Users who want its functionality can continue to import x/exp/maps.
The text was updated successfully, but these errors were encountered: