Skip to content

Commit

Permalink
update utilities.MergeMaps
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettladley committed May 18, 2024
1 parent 123e25c commit da90b99
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions backend/utilities/map.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package utilities

// MergeMaps merges multiple maps into a single map.
// The keys of maps earlier in the list will take precedence over keys in later maps.
func MergeMaps[K comparable, V any](maps ...map[K]V) map[K]V {
merged := make(map[K]V)

for _, m := range maps {
for key, value := range m {
merged[key] = value
for index := len(maps) - 1; index >= 0; index-- {
for k, v := range maps[index] {
merged[k] = v
}
}

Expand Down

0 comments on commit da90b99

Please sign in to comment.