From e06c8e3463e7fb54a4e4e093a471285259be59f5 Mon Sep 17 00:00:00 2001 From: charlie <3140647@qq.com> Date: Fri, 22 Apr 2022 16:36:01 +0800 Subject: [PATCH] String() --- sort/sort.go | 7 +++++++ sort/sort_test.go | 3 +++ 2 files changed, 10 insertions(+) diff --git a/sort/sort.go b/sort/sort.go index a8b0b04..58a9046 100644 --- a/sort/sort.go +++ b/sort/sort.go @@ -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 { diff --git a/sort/sort_test.go b/sort/sort_test.go index 133f316..f5ceeae 100644 --- a/sort/sort_test.go +++ b/sort/sort_test.go @@ -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)