1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-11 08:12:26 +08:00

feat: add Minus func

This commit is contained in:
dudaodong
2022-03-31 18:00:11 +08:00
parent bf7ffbfa8d
commit 19939c2b03
2 changed files with 32 additions and 1 deletions

View File

@@ -60,7 +60,7 @@ func Filter[K comparable, V any](m map[K]V, predicate func(key K, value V) bool)
return res
}
// Intersect iterates over maps, return a new map of key and value pairs in all give maps
// Intersect iterates over maps, return a new map of key and value pairs in all given maps
func Intersect[K comparable, V any](maps ...map[K]V) map[K]V {
if len(maps) == 0 {
return map[K]V{}
@@ -92,3 +92,16 @@ func Intersect[K comparable, V any](maps ...map[K]V) map[K]V {
return res
}
// Minus creates an map of whose key in mapA but not in mapB
func Minus[K comparable, V any](mapA, mapB map[K]V) map[K]V {
res := make(map[K]V)
for k, v := range mapA {
if _, ok := mapB[k]; !ok {
res[k] = v
}
}
return res
}