Skip to content

Commit

Permalink
shared/util: Add a function to clone maps
Browse files Browse the repository at this point in the history
Signed-off-by: montag451 <[email protected]>
  • Loading branch information
montag451 committed Nov 19, 2024
1 parent c7dd60d commit 355ee53
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions shared/util/map.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package util

import (
"maps"
)

// CloneMap returns a copy of m. This is a shallow clone: the new keys
// and values are set using ordinary assignment.
func CloneMap[M ~map[K]V, K comparable, V any](m M) M {
if m == nil {
return make(map[K]V)
}

return maps.Clone(m)
}

0 comments on commit 355ee53

Please sign in to comment.