From 9b16af97754bd2ffac4c6397747339aa9c63a24c Mon Sep 17 00:00:00 2001 From: tx7do Date: Wed, 25 Oct 2023 14:53:43 +0800 Subject: [PATCH] feat: transfer utils. --- trans/trans.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/trans/trans.go b/trans/trans.go index 10e7ef5..f20c5e7 100644 --- a/trans/trans.go +++ b/trans/trans.go @@ -502,3 +502,28 @@ func BoolSliceValue(a []*bool) []bool { } return res } + +type mapKeyValueType interface { + ~string | ~bool | + ~int | ~int8 | ~int16 | ~int32 | + ~uint | ~uint8 | ~uint16 | ~uint32 | + ~float32 | ~float64 +} + +// MapKeys 获取map的键 +func MapKeys[TKey mapKeyValueType, TValue mapKeyValueType](source map[TKey]TValue) []TKey { + var target []TKey + for k := range source { + target = append(target, k) + } + return target +} + +// MapValues 获取map的值 +func MapValues[TKey mapKeyValueType, TValue mapKeyValueType](source map[TKey]TValue) []TValue { + var target []TValue + for _, v := range source { + target = append(target, v) + } + return target +}