Standard library / maps
maps.Copy()
Copies source entries into the destination, replacing matching keys but retaining unrelated destination entries. A nil destination panics if a write occurs. Expected stdout: '9 2\n'.
Formal Syntax & Structure
go syntaxgo
func Copy[M1 ~map[K]V, M2 ~map[K]V, K comparable, V any](dst M1, src M2)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| dst | M1 | Destination map; must support writes if entries are inserted. |
| src | M2 | Source map. |
Working Example
Example Snippetgo
package main
import ( "fmt" "maps")
func main() { a := map[string]int{"a": 1, "b": 2} maps.Copy(a, map[string]int{"a": 9}) fmt.Println(a["a"], a["b"])}