diff --git a/utils/collection/map.go b/utils/collection/map.go index 10b3eeb..6a8a72b 100644 --- a/utils/collection/map.go +++ b/utils/collection/map.go @@ -1,7 +1,7 @@ package collection // MappingFromSlice 将切片中的元素进行转换 -func MappingFromSlice[S ~[]V, NS ~[]N, V, N any](slice S, handler func(value V) N) NS { +func MappingFromSlice[S ~[]V, NS []N, V, N any](slice S, handler func(value V) N) NS { if slice == nil { return nil } @@ -13,7 +13,7 @@ func MappingFromSlice[S ~[]V, NS ~[]N, V, N any](slice S, handler func(value V) } // MappingFromMap 将 map 中的元素进行转换 -func MappingFromMap[M ~map[K]V, NM ~map[K]N, K comparable, V, N any](m M, handler func(value V) N) NM { +func MappingFromMap[M ~map[K]V, NM map[K]N, K comparable, V, N any](m M, handler func(value V) N) NM { if m == nil { return nil } diff --git a/utils/collection/map_example_test.go b/utils/collection/map_example_test.go index e51b876..d26b712 100644 --- a/utils/collection/map_example_test.go +++ b/utils/collection/map_example_test.go @@ -1,9 +1,12 @@ -package collection +package collection_test -import "fmt" +import ( + "fmt" + "github.com/kercylan98/minotaur/utils/collection" +) func ExampleMappingFromSlice() { - result := MappingFromSlice[[]int, []int]([]int{1, 2, 3}, func(value int) int { + result := collection.MappingFromSlice([]int{1, 2, 3}, func(value int) int { return value + 1 }) fmt.Println(result) @@ -12,7 +15,7 @@ func ExampleMappingFromSlice() { } func ExampleMappingFromMap() { - result := MappingFromMap[map[int]int, map[int]int](map[int]int{1: 1, 2: 2, 3: 3}, func(value int) int { + result := collection.MappingFromMap(map[int]int{1: 1, 2: 2, 3: 3}, func(value int) int { return value + 1 }) fmt.Println(result) diff --git a/utils/collection/random.go b/utils/collection/random.go index cdb8816..03e43fe 100644 --- a/utils/collection/random.go +++ b/utils/collection/random.go @@ -101,7 +101,7 @@ func ChooseRandomMapKeyRepeatN[M ~map[K]V, K comparable, V any](m M, n int) (res return } -// ChooseRandomMapValueRepeatN 获取 map 中的 n 个随机 inputV,允许重复 +// ChooseRandomMapValueRepeatN 获取 map 中的 n 个随机 n,允许重复 // - 如果 n 大于 map 长度或小于 0 时将会发生 panic func ChooseRandomMapValueRepeatN[M ~map[K]V, K comparable, V any](m M, n int) (result []V) { if m == nil { @@ -150,7 +150,7 @@ func ChooseRandomMapKey[M ~map[K]V, K comparable, V any](m M) (k K) { return } -// ChooseRandomMapValue 获取 map 中的随机 inputV +// ChooseRandomMapValue 获取 map 中的随机 value func ChooseRandomMapValue[M ~map[K]V, K comparable, V any](m M) (v V) { if m == nil { return @@ -182,8 +182,8 @@ func ChooseRandomMapKeyN[M ~map[K]V, K comparable, V any](m M, n int) (result [] return } -// ChooseRandomMapValueN 获取 map 中的 inputN 个随机 inputV -// - 如果 inputN 大于 map 长度或小于 0 时将会发生 panic +// ChooseRandomMapValueN 获取 map 中的 n 个随机 value +// - 如果 n 大于 map 长度或小于 0 时将会发生 panic func ChooseRandomMapValueN[M ~map[K]V, K comparable, V any](m M, n int) (result []V) { if m == nil { return