# Functions
Entries transforms a map into array of key/value pairs.
Filter iterates over map, return a new map contains all key and value pairs pass the predicate function.
FilterByKeys iterates over map, return a new map whose keys are all given keys.
FilterByValues iterates over map, return a new map whose values are all given values.
ForEach executes iteratee funcation for every key and value pair in map.
FromEntries creates a map based on a slice of key/value pairs Play: https://go.dev/play/p/fTdu4sCNjQO.
GetOrDefault returns the value of the given key or a default value if the key is not present.
GetOrSet returns value of the given key or set the given value value if not present.
HasKey checks if map has key or not.
Intersect iterates over maps, return a new map of key and value pairs in all given maps.
IsDisjoint two map are disjoint if they have no keys in common.
Keys returns a slice of the map's keys.
KeysBy creates a slice whose element is the result of function mapper invoked by every map's key.
MapKeys transforms a map to other type map by manipulating it's keys.
MapTo try to map any interface to struct or base type
Eg:
v := map[string]interface{}{
"service":map[string]interface{}{
"ip":"127.0.0.1",
"port":1234,
},
version:"v1.0.01"
}
type Target struct {
Service struct {
Ip string `json:"ip"`
Port int `json:"port"`
} `json:"service"`
Ver string `json:"version"`
}
var dist Target
if err := maputil.MapTo(v,&dist); err != nil {
log.Println(err)
return
}
log.Println(dist)
*/ Play: https://go.dev/play/p/4K7KBEPgS5M.
MapToStruct converts map to struct Play: https://go.dev/play/p/7wYyVfX38Dp.
MapValues transforms a map to other type map by manipulating it's values.
Merge maps, next key will overwrite previous key.
Minus creates a map of whose key in mapA but not in mapB.
NewConcurrentMap create a ConcurrentMap with specific shard count.
NewOrderedMap creates a new OrderedMap.
OmitBy is the opposite of Filter, removes all the map elements for which the predicate function returns true.
OmitByKeys the opposite of FilterByKeys, extracts all the map elements which keys are not omitted.
OmitByValues the opposite of FilterByValues.
SortByKey sorts the map by its keys and returns a new map with sorted keys.
ToSortedSlicesDefault converts a map to two slices sorted by key: one for the keys and another for the values.
ToSortedSlicesWithComparator converts a map to two slices sorted by key and using a custom comparison function: one for the keys and another for the values.
Transform a map to another type map.
Values returns a slice of the map's values.
ValuesBy creates a slice whose element is the result of function mapper invoked by every map's value.
# Structs
ConcurrentMap is like map, but is safe for concurrent use by multiple goroutines.
Entry is a key/value pairs.
OrderedMap is a map that maintains the order of keys.