This commit is contained in:
Kovid Goyal 2022-09-21 10:51:43 +05:30
parent d0e133885c
commit e7f38929d9
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 7 additions and 5 deletions

View File

@ -368,8 +368,7 @@ func (self *Command) CommandStringForUsage(args []string) string {
} }
p = p.Parent p = p.Parent
} }
utils.Reverse(names) return strings.Join(utils.Reverse(names), " ")
return strings.Join(names, " ")
} }
func (self *Command) ParseArgs(args []string) (*Command, error) { func (self *Command) ParseArgs(args []string) (*Command, error) {

View File

@ -9,10 +9,11 @@ import (
var _ = fmt.Print var _ = fmt.Print
func Reverse[T any](s []T) { func Reverse[T any](s []T) []T {
for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 { for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
s[i], s[j] = s[j], s[i] s[i], s[j] = s[j], s[i]
} }
return s
} }
func Reversed[T any](s []T) []T { func Reversed[T any](s []T) []T {
@ -23,10 +24,12 @@ func Reversed[T any](s []T) []T {
return ans return ans
} }
func Sort[T any](s []T, less func(a, b T) bool) { func Sort[T any](s []T, less func(a, b T) bool) []T {
sort.Slice(s, func(i, j int) bool { return less(s[i], s[j]) }) sort.Slice(s, func(i, j int) bool { return less(s[i], s[j]) })
return s
} }
func StableSort[T any](s []T, less func(a, b T) bool) { func StableSort[T any](s []T, less func(a, b T) bool) []T {
sort.SliceStable(s, func(i, j int) bool { return less(s[i], s[j]) }) sort.SliceStable(s, func(i, j int) bool { return less(s[i], s[j]) })
return s
} }