-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
maps: new standard library package based on x/exp/maps #57436
Comments
Isn’t Clear obsoleted by the new clear builtin? |
Thanks. I think you're right. I've edited the proposal to remove |
I would love to see either a new type |
@iamemilio Seems out of scope for this proposal. References:
|
A concern I've had with EqualFunc before is it compares length first, so you can't use it if you want to consider m1 and m2 the same if any keys missing from one or the other have zero values. E.g., these two maps might be considered equivalent for some applications: var m1 = map[string]int {
"a": 0,
"b": 0,
"c": 0,
}
var m2 = map[string]int {
"b": 0,
"c": 0,
"d": 0,
}
eq := true
for k := range m1 {
if m1[k] != m2[k] {
eq = false
}
}
for k := range m2 {
if m1[k] != m2[k] {
eq = false
}
}
fmt.Println(eq) // true Maybe the solution is to add a looser but slower function with a name like |
This comment was marked as resolved.
This comment was marked as resolved.
This proposal has been added to the active column of the proposals project |
@carlmjohnson if you feel strongly about Equivalent being in the package that should be a separate proposal. It seems a little niche to me. |
Given that we already reviewed this API before it went into x/exp, it is not surprising there's not much discussion here. The proposal is exactly x/exp/maps minus Clear. Does anyone object to accepting this proposal? |
Based on the discussion above, this proposal seems like a likely accept. |
I would like to bring up #56621 again, now that x/exp/maps is on its way to the standard library. I feel like there should at least be an example showing this behaviour. Other than that, the API would be a welcome addition to the stdlib. |
I don't think that anything has changed regarding #56621. Of course examples are always welcome. |
No change in consensus, so accepted. 🎉 |
Change https://go.dev/cl/464343 mentions this issue: |
This copies x/exp/maps into the standard library (except for the Clear function which is now available as the clear builtin.) Fixes golang#57436 Change-Id: I30dd470c2f7ae34c7c82b4c1025a7582d61fabaa Reviewed-on: https://go-review.googlesource.com/c/go/+/464343 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Eli Bendersky <eliben@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com>
Change https://go.dev/cl/498602 mentions this issue: |
For #57436 Change-Id: I99e8b0819c76f1ccf12154a894c9c4c9d68124d4 Reviewed-on: https://go-review.googlesource.com/c/go/+/498602 Reviewed-by: Eli Bendersky <eliben@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com>
|
This copies x/exp/maps into the standard library (except for the Clear function which is now available as the clear builtin.) Fixes golang#57436 Change-Id: I30dd470c2f7ae34c7c82b4c1025a7582d61fabaa Reviewed-on: https://go-review.googlesource.com/c/go/+/464343 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Eli Bendersky <eliben@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com>
This copies x/exp/maps into the standard library (except for the Clear function which is now available as the clear builtin.) Fixes golang#57436 Change-Id: I30dd470c2f7ae34c7c82b4c1025a7582d61fabaa Reviewed-on: https://go-review.googlesource.com/c/go/+/464343 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Eli Bendersky <eliben@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com>
In #47649 @rsc proposed a new maps package in the standard library based on discussion in #47330. After we settled on an API we added the experimental package golang.org/x/exp/maps.
We now have experience with this package in practice. pkg.go.dev reports that it is imported by 615 other packages. I propose that it is now time to move this package into the standard library for the 1.21 release.
Doing this doesn't mean that we can't add more functions to the standard library maps package later. Any such additions should be suggested in their own separate proposal. (There are some existing proposals that would move from x/exp/maps to maps: at least #54012, #54454, #57191).
The specific API that we will put into the standard library is as follows.
The text was updated successfully, but these errors were encountered: