Files
go-easy-utils/mapx/exists.go
2025-07-08 15:26:54 +08:00

18 lines
361 B
Go

package mapx
// KeyExists 判断map中的key是否存在
func KeyExists[T comparable, T2 any](m map[T]T2, key T) bool {
_, exists := m[key]
return exists
}
// ValueExists 判断map中的value是否存在
func ValueExists[T comparable, T2 comparable](m map[T2]T, value T) bool {
for _, v := range m {
if v == value {
return true
}
}
return false
}