Standard library / maps

maps.Insert()

Inserts pairs from an iterator, replacing matching keys. Destination must be initialized if the sequence produces entries. Expected stdout: '1 2\n'.

Formal Syntax & Structure

go syntaxgo
func Insert[Map ~map[K]V, K comparable, V any](m Map, seq iter.Seq2[K, V])

Parameters & Attributes

NameTypeDescription
mMapInput map.
seqiter.Seq2[K, V]Iterator function producing the input sequence.

Working Example

Example Snippetgo
package main
import (  "fmt"  "maps")
func main() {  a := map[string]int{"a": 1}  maps.Insert(a, maps.All(map[string]int{"b": 2}))  fmt.Println(a["a"], a["b"])}
Go Reference