From baae69de1517a148f729f214fe94cda0ba662612 Mon Sep 17 00:00:00 2001 From: Inhere Date: Tue, 4 Oct 2022 12:20:50 +0800 Subject: [PATCH] up: rename str convert to conv.go --- arrutil/arrutil.go | 18 ++++++++++++++++-- stdutil/{convert.go => conv.go} | 0 stdutil/{convert_test.go => conv_test.go} | 0 3 files changed, 16 insertions(+), 2 deletions(-) rename stdutil/{convert.go => conv.go} (100%) rename stdutil/{convert_test.go => conv_test.go} (100%) diff --git a/arrutil/arrutil.go b/arrutil/arrutil.go index 78d488e1b..38158ffa6 100644 --- a/arrutil/arrutil.go +++ b/arrutil/arrutil.go @@ -68,7 +68,7 @@ func StringsMap(ss []string, mapFn func(s string) string) []string { // // // output: [a, b, c] // ss := arrutil.TrimStrings([]string{",a", "b.", ",.c,"}, ",.") -func TrimStrings(ss []string, cutSet ...string) (ns []string) { +func TrimStrings(ss []string, cutSet ...string) []string { cutSetLn := len(cutSet) hasCutSet := cutSetLn > 0 && cutSet[0] != "" @@ -80,6 +80,7 @@ func TrimStrings(ss []string, cutSet ...string) (ns []string) { trimSet = strings.Join(cutSet, "") } + ns := make([]string, 0, len(ss)) for _, str := range ss { if hasCutSet { ns = append(ns, strings.Trim(str, trimSet)) @@ -87,7 +88,7 @@ func TrimStrings(ss []string, cutSet ...string) (ns []string) { ns = append(ns, strings.TrimSpace(str)) } } - return + return ns } // GetRandomOne get random element from an array/slice @@ -104,3 +105,16 @@ func RandomOne(arr interface{}) interface{} { r := rv.Index(i).Interface() return r } + +// Unique value in the given array, slice. +func Unique(arr interface{}) interface{} { + rv := reflect.ValueOf(arr) + if rv.Kind() != reflect.Slice && rv.Kind() != reflect.Array { + return arr + } + + for i := 0; i < rv.Len(); i++ { + // TODO ... + } + return arr +} diff --git a/stdutil/convert.go b/stdutil/conv.go similarity index 100% rename from stdutil/convert.go rename to stdutil/conv.go diff --git a/stdutil/convert_test.go b/stdutil/conv_test.go similarity index 100% rename from stdutil/convert_test.go rename to stdutil/conv_test.go