DRYer
This commit is contained in:
parent
d0e133885c
commit
e7f38929d9
@ -368,8 +368,7 @@ func (self *Command) CommandStringForUsage(args []string) string {
|
||||
}
|
||||
p = p.Parent
|
||||
}
|
||||
utils.Reverse(names)
|
||||
return strings.Join(names, " ")
|
||||
return strings.Join(utils.Reverse(names), " ")
|
||||
}
|
||||
|
||||
func (self *Command) ParseArgs(args []string) (*Command, error) {
|
||||
|
||||
@ -9,10 +9,11 @@ import (
|
||||
|
||||
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 {
|
||||
s[i], s[j] = s[j], s[i]
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
func Reversed[T any](s []T) []T {
|
||||
@ -23,10 +24,12 @@ func Reversed[T any](s []T) []T {
|
||||
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]) })
|
||||
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]) })
|
||||
return s
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user