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.
Click to show internal directories.
Click to hide internal directories.