Feature/generic type (#19)

Supports generics and any
This commit is contained in:
jeffery
2023-04-07 19:21:05 +08:00
committed by GitHub
parent ce429aed1f
commit 9a8c60b30a
51 changed files with 348 additions and 1127 deletions

View File

@@ -1,7 +1,7 @@
package mapUtil
// MapValueExists 判断map中的value是否存在
func MapValueExists(m map[string]interface{}, value interface{}) bool {
func MapValueExists[T comparable](m map[string]T, value T) bool {
for _, v := range m {
if v == value {
return true
@@ -11,7 +11,7 @@ func MapValueExists(m map[string]interface{}, value interface{}) bool {
}
// MapKeyExists 判断map中的key是否存在
func MapKeyExists(m map[string]interface{}, key string) bool {
func MapKeyExists(m map[string]any, key string) bool {
_, exists := m[key]
return exists
}