mirror of
https://github.com/jefferyjob/go-easy-utils.git
synced 2025-10-27 00:50:22 +08:00
@@ -1,7 +1,13 @@
|
||||
package mapUtil
|
||||
|
||||
// MapKeyExists 判断map中的key是否存在
|
||||
func MapKeyExists[T comparable, T2 any](m map[T]T2, key T) bool {
|
||||
_, exists := m[key]
|
||||
return exists
|
||||
}
|
||||
|
||||
// MapValueExists 判断map中的value是否存在
|
||||
func MapValueExists[T comparable](m map[string]T, value T) bool {
|
||||
func MapValueExists[T comparable, T2 comparable](m map[T2]T, value T) bool {
|
||||
for _, v := range m {
|
||||
if v == value {
|
||||
return true
|
||||
@@ -9,9 +15,3 @@ func MapValueExists[T comparable](m map[string]T, value T) bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// MapKeyExists 判断map中的key是否存在
|
||||
func MapKeyExists(m map[string]any, key string) bool {
|
||||
_, exists := m[key]
|
||||
return exists
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user