Documentation
¶
Overview ¶
Package maps provides utility functions for handling maps, and transitioning between maps and slices.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Dedup ¶
func Dedup(a interface{}) interface{}
Dedup returns a copy of the given slice, sorted and with no duplicated values. For non-comparable types, removes duplicates without sorting. Input slice is unchanged.
func Keys ¶
func Keys(a interface{}) interface{}
Keys returns the keys of the given map in a sorted slice.
For a map of type map[k]v, result is of type []k.
Example ¶
m := map[string]int{
"a": 1,
"c": 3,
"b": 2,
}
keys := Keys(m).([]string)
fmt.Println(keys)
Output: [a b c]
func Of ¶
func Of(slice interface{}, value interface{}) interface{}
Of returns a map whose keys are the values of the given slice, and all have the same given value.
For a slice of type []k and value of type v, result is of type map[k]v.
Example ¶
people := []string{"alice", "bob"}
m := Of(people, true).(map[string]bool)
fmt.Println("'alice' in map:", m["alice"])
fmt.Println("'bob' in map:", m["bob"])
fmt.Println("'charles' in map:", m["charles"])
Output: 'alice' in map: true 'bob' in map: true 'charles' in map: false
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.