Documentation
¶
Index ¶
- func Copy[K comparable, V any](mapInstance map[K]V) map[K]Vdeprecated
- func Drop[K comparable, V any](mapInstance map[K]V, keys []K) map[K]V
- func Filter[K comparable, V any](mapInstance map[K]V, function func(key K, value V) bool) map[K]V
- func ForEach[K comparable, V any](mapInstance map[K]V, function func(key K, value V))
- func FromEntries[K comparable, V any](entries [][2]any) map[K]V
- func Get[K comparable, V any](mapInstance map[K]V, key K, defaultValue V) V
- func GroupBy[K comparable, V any, G comparable](mapInstance map[K]V, grouper func(key K, value V) G) map[G]map[K]V
- func Has[K comparable, V any](mapInstance map[K]V, key K) bool
- func Invert[K, V comparable](mapInstance map[K]V) map[V]K
- func Keys[K comparable, V any](mapInstance map[K]V) []K
- func Map[K comparable, V any, R any](mapInstance map[K]V, mapper func(key K, value V) R) map[K]R
- func MapKeys[K comparable, V any, R comparable](mapInstance map[K]V, mapper func(key K, value V) R) map[R]V
- func Merge[K comparable, V any](mapInstances ...map[K]V) map[K]V
- func Omit[K comparable, V any](mapInstance map[K]V, keys []K) map[K]V
- func Pick[K comparable, V any](mapInstance map[K]V, keys []K) map[K]V
- func ToEntries[K comparable, V any](mapInstance map[K]V) [][2]any
- func Values[K comparable, V any](mapInstance map[K]V) []V
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Copy
deprecated
func Copy[K comparable, V any](mapInstance map[K]V) map[K]V
Copy - takes a map with keys K and values V and returns a copy of the map.
Deprecated: Copy is deprecated as of Go 1.21. Use maps.Clone from the standard library instead:
import "maps" copied := maps.Clone(original)
This function will be removed in a future major version.
func Drop ¶
func Drop[K comparable, V any](mapInstance map[K]V, keys []K) map[K]V
Drop - takes a map with keys K and values V, and a slice of keys K, dropping all the key-value pairs that match the keys in the slice. Note: this function will modify the passed in map. To get a different object, use the Copy function to pass a copy to this function.
func Filter ¶
func Filter[K comparable, V any](mapInstance map[K]V, function func(key K, value V) bool) map[K]V
Filter - takes a map with keys K and values V, and executes the passed in function for each key-value pair. If the filter function returns true, the key-value pair will be included in the output, otherwise it is filtered out.
func ForEach ¶
func ForEach[K comparable, V any](mapInstance map[K]V, function func(key K, value V))
ForEach - given a map with keys K and values V, executes the passed in function for each key-value pair.
func FromEntries ¶ added in v1.9.0
func FromEntries[K comparable, V any](entries [][2]any) map[K]V
FromEntries creates a map from a slice of key-value pairs. If duplicate keys exist, later values overwrite earlier ones.
func Get ¶ added in v1.9.0
func Get[K comparable, V any](mapInstance map[K]V, key K, defaultValue V) V
Get safely gets a value from the map with a default fallback if the key doesn't exist.
func GroupBy ¶ added in v1.9.0
func GroupBy[K comparable, V any, G comparable]( mapInstance map[K]V, grouper func(key K, value V) G, ) map[G]map[K]V
GroupBy groups map entries by a grouping key generated from each entry. Returns a map where keys are group identifiers and values are maps of entries belonging to that group.
func Has ¶ added in v1.9.0
func Has[K comparable, V any](mapInstance map[K]V, key K) bool
Has checks if a key exists in the map.
func Invert ¶ added in v1.9.0
func Invert[K, V comparable](mapInstance map[K]V) map[V]K
Invert swaps keys and values in a map. Note: If multiple keys have the same value, only one will remain (non-deterministic which one). Both keys and values must be comparable types.
func Keys ¶
func Keys[K comparable, V any](mapInstance map[K]V) []K
Keys - takes a map with keys K and values V, returns a slice of type K of the map's keys. Note: Go maps do not preserve insertion order.
func Map ¶ added in v1.9.0
func Map[K comparable, V any, R any](mapInstance map[K]V, mapper func(key K, value V) R) map[K]R
Map transforms map values using a mapper function, returning a new map with transformed values.
func MapKeys ¶ added in v1.9.0
func MapKeys[K comparable, V any, R comparable]( mapInstance map[K]V, mapper func(key K, value V) R, ) map[R]V
MapKeys transforms map keys using a mapper function, returning a new map with transformed keys. Note: If the mapper produces duplicate keys, later values will overwrite earlier ones.
func Merge ¶
func Merge[K comparable, V any](mapInstances ...map[K]V) map[K]V
Merge - takes an arbitrary number of map instances with keys K and values V and merges them into a single map. Note: merge works from left to right. If a key already exists in a previous map, its value is over-written.
func Omit ¶ added in v1.9.0
func Omit[K comparable, V any](mapInstance map[K]V, keys []K) map[K]V
Omit creates a new map excluding the specified keys.
func Pick ¶ added in v1.9.0
func Pick[K comparable, V any](mapInstance map[K]V, keys []K) map[K]V
Pick creates a new map containing only the specified keys. Keys that don't exist in the original map are ignored.
func ToEntries ¶ added in v1.9.0
func ToEntries[K comparable, V any](mapInstance map[K]V) [][2]any
ToEntries converts a map to a slice of key-value pairs. Note: Order is non-deterministic due to map iteration order.
func Values ¶
func Values[K comparable, V any](mapInstance map[K]V) []V
Values - takes a map with keys K and values V, returns a slice of type V of the map's values. Note: Go maps do not preserve insertion order.
Types ¶
This section is empty.