1
0
mirror of https://github.com/charlienet/go-mixed.git synced 2025-07-17 16:12:42 +08:00
This commit is contained in:
2022-04-22 16:36:01 +08:00
parent 6977900201
commit e06c8e3463
2 changed files with 10 additions and 0 deletions

View File

@ -1,6 +1,7 @@
package sort
import (
"fmt"
"sort"
"strings"
)
@ -59,6 +60,12 @@ func (s *mapSorter[T]) Values() []T {
return ret
}
func (s *mapSorter[T]) String() string {
return fmt.Sprintf("map[%s]", s.Join(" ", func(k string, v T) string {
return fmt.Sprintf("%s:%v", k, v)
}))
}
func keys[T any](m map[string]T) []string {
keys := make([]string, 0, len(m))
for k := range m {

View File

@ -23,6 +23,8 @@ func TestMapSortInt(t *testing.T) {
}
ret := SortByKey(m).Desc().Values()
t.Log(SortByKey(m).Desc())
t.Log(SortByKey(m).Asc())
t.Log(ret)
}
@ -33,6 +35,7 @@ func TestJoin(t *testing.T) {
"Abc": "abc",
"Efg": "efg",
}
t.Log(m)
j := SortByKey(m).Asc().Join("&", func(k string, v any) string {
return fmt.Sprintf("%s=%v", k, v)