Skip to content

Commit

Permalink
add map merge function (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
zreigz authored Mar 5, 2024
1 parent c914ce3 commit 7efbdc5
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions algorithms/map.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package algorithms

func Merge(m1, m2 map[string]interface{}) map[string]interface{} {
// lifted from helm's merge code
out := make(map[string]interface{}, len(m1))
for k, v := range m1 {
out[k] = v
}

for k, v := range m2 {
if v, ok := v.(map[string]interface{}); ok {
if bv, ok := out[k]; ok {
if bv, ok := bv.(map[string]interface{}); ok {
out[k] = Merge(bv, v)
continue
}
}
}
out[k] = v
}
return out
}

0 comments on commit 7efbdc5

Please sign in to comment.