github.com/isyscore/isc-gobase@v1.5.3-0.20231218061332-cbc7451899e9/isc/equal.go (about) 1 package isc 2 3 import "reflect" 4 5 // ListEquals 比较两个数组是否相同 6 func ListEquals[T any](leftList []T, rightList []T) bool { 7 if leftList == nil && rightList == nil { 8 return true 9 } 10 if leftList == nil || rightList == nil { 11 return false 12 } 13 if len(leftList) != len(rightList) { 14 return false 15 } 16 l := ListDistinct(append(leftList, rightList...)) 17 return len(l) == len(leftList) 18 } 19 20 // MapEquals 比较两个map是否相同 21 func MapEquals[K comparable, V any](leftMap map[K]V, rightMap map[K]V) bool { 22 if leftMap == nil && rightMap == nil { 23 return true 24 } 25 if leftMap == nil || rightMap == nil { 26 return false 27 } 28 if len(leftMap) != len(rightMap) { 29 return false 30 } 31 32 for key, leftValue := range leftMap { 33 rightValue, exist := rightMap[key] 34 if !exist || !reflect.DeepEqual(rightValue, leftValue) { 35 return false 36 } 37 } 38 return true 39 }