Add MapOmit, Context Parse/Serialize
This commit is contained in:
17
struct.go
17
struct.go
@@ -43,6 +43,23 @@ func StructHasProperty(value interface{}, name string) bool {
|
||||
return has
|
||||
}
|
||||
|
||||
func MapOmit[K comparable, V any](m map[K]V, keys ...K) map[K]V {
|
||||
out := make(map[K]V, len(m))
|
||||
|
||||
omit := make(map[K]struct{}, len(keys))
|
||||
for _, k := range keys {
|
||||
omit[k] = struct{}{}
|
||||
}
|
||||
|
||||
for k, v := range m {
|
||||
if _, ok := omit[k]; !ok {
|
||||
out[k] = v
|
||||
}
|
||||
}
|
||||
|
||||
return out
|
||||
}
|
||||
|
||||
// MapMerge merges maps into one.
|
||||
func MapMerge[T ~map[string]any](maps...T) T {
|
||||
out := make(T)
|
||||
|
||||
Reference in New Issue
Block a user