-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
refactor: replace golang.org/x/exp
with stdlib
#23501
Conversation
These experimental packages are now available in the Go standard library since Go 1.21 and Go 1.23: 1. golang.org/x/exp/slices -> slices [1] 2. golang.org/x/exp/maps -> maps [2] [1]: https://go.dev/doc/go1.21#slices [2]: https://go.dev/doc/go1.21#maps [3]: https://go.dev/doc/go1.23#iterators Signed-off-by: Eng Zer Jun <[email protected]>
📝 WalkthroughWalkthroughThis pull request focuses on updating the codebase to utilize standard library packages instead of external experimental packages. Key changes include replacing imports from Changes
Possibly related PRs
Suggested Labels
Suggested Reviewers
📜 Recent review detailsConfiguration used: .coderabbit.yml ⛔ Files ignored due to path filters (2)
📒 Files selected for processing (3)
💤 Files with no reviewable changes (1)
🚧 Files skipped from review as they are similar to previous changes (2)
⏰ Context from checks skipped due to timeout of 90000ms (13)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have performed a self-review of my code changes.
func OrderedMapKeys[K constraints.Ordered, V any](m map[K]V) []K { | ||
keys := maps.Keys(m) | ||
slices.Sort(keys) | ||
return keys | ||
func OrderedMapKeys[K cmp.Ordered, V any](m map[K]V) []K { | ||
return slices.Sorted(maps.Keys(m)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned in the PR description, this is the only difference between maps.Keys
from the golang.org/x/exp/maps
package and the standard library maps
package.
For reference, see https://pkg.go.dev/maps#Keys and https://pkg.go.dev/slices#Collect
@Juneezee thanks for opening this! this is something we've been meaning to do :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this! Originally we didn't do it there to not have to bump the minimum go version. But given probably nobody should build their in a version less than go 1.23 in feb that's fine 👍🏾
Description
These experimental packages are now available in the Go standard library since Go 1.21 and Go 1.23:
golang.org/x/exp/slices
->slices
(https://go.dev/doc/go1.21#slices)golang.org/x/exp/maps
->maps
(https://go.dev/doc/go1.21#maps)The key difference is that
maps.Keys
in thegolang.org/x/exp/maps
package return a slice, whereasmaps.Keys
in the standard library return an iterator. To work with slices, we need to useslices.Collect
to convert the iterator into a slice.Reference: https://go.dev/doc/go1.23#iterators
Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
confirmedNo breaking change!
in the type prefix if API or client breaking changeincluded the necessary unit and integration testsRefactor only. No new features or behavior changeadded a changelog entry toNo user-facing changesCHANGELOG.md
updated the relevant documentation or specification, including comments for documenting Go codeRefactor only. No new features or behavior changeReviewers Checklist
All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.
Please see Pull Request Reviewer section in the contributing guide for more information on how to review a pull request.
I have...
Summary by CodeRabbit
Release Notes
Dependencies
golang.org/x/exp
Package Updates
constraints.Ordered
tocmp.Ordered
Performance
These changes primarily focus on modernizing package dependencies and improving code clarity without altering core functionality.