maps

package
v1.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 2, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitMap

func InitMap[K comparable, V any, T ~map[K]V](m *T)

InitMap initializes a map pointer if it is nil. If the map is already initialized, this function does nothing.

This is useful for ensuring a map is ready to use before adding entries, preventing nil pointer dereferences.

Example:

var m map[string]int
InitMap(&m)
m["key"] = 42 // safe to use

func UpdateMap

func UpdateMap[K comparable, V any, T ~map[K]V](oldMap *T, newMap T)

UpdateMap merges entries from the new map into the old map. If the old map is nil, it will be initialized first. Existing keys in the old map will be overwritten with values from the new map.

This function modifies the old map in place by copying all key-value pairs from the new map into it.

Example:

old := map[string]int{"a": 1, "b": 2}
new := map[string]int{"b": 3, "c": 4}
UpdateMap(&old, new)
// old is now: {"a": 1, "b": 3, "c": 4}

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL