Add MapMerge

This commit is contained in:
George Suntres
2026-04-22 10:00:02 -04:00
parent f0bb6adf71
commit 55de9c34e8
2 changed files with 32 additions and 4 deletions

View File

@@ -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 {