-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Closed
Milestone
Description
During the review of the proposal for the new slices package I mentioned that Reverse, a common slice operation, seemed to be missing, and was advised to file a separate proposal. So here it is. I propose we add this function:
package slices
// Reverse reverses the elements of the slice in place.
func Reverse[S ~[]E, E any](s S) {
for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
s[i], s[j] = s[j], s[i]
}
}
You can see the full implementation in https://go.dev/cl/468855. ;-)
Reactions are currently unavailable