Add MapMerge
This commit is contained in:
15
struct.go
15
struct.go
@@ -43,6 +43,21 @@ func StructHasProperty(value interface{}, name string) bool {
|
||||
return has
|
||||
}
|
||||
|
||||
// MapMerge merges maps into one.
|
||||
func MapMerge[T ~map[string]any](maps...T) T {
|
||||
out := make(T)
|
||||
|
||||
for _, m := range maps {
|
||||
if m != nil {
|
||||
for k, v := range m {
|
||||
out[k] = v
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return out
|
||||
}
|
||||
|
||||
// StructMustTomap given any struct return the equivalent map[string]any or nil.
|
||||
// Will never throw.
|
||||
func StructMustToMap(data any) map[string]any {
|
||||
|
||||
Reference in New Issue
Block a user