Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ToSlice ¶
func ToSlice[M ~map[K]V, K comparable, V, R any](items M, f func(K, V) R) []R
ToSlice applies the function to each element of the input map, and returns an array of the results.
Example ¶
nums := map[string]int{
"one": 1,
"two": 2,
"three": 3,
}
fn := func(k string, v int) string {
return fmt.Sprintf("%d in text is %s", v, k)
}
results := ToSlice(nums, fn)
sort.Strings(results) // order is not guaranteed for map keys
fmt.Println(results)
Output: [1 in text is one 2 in text is two 3 in text is three]
func ToValues ¶
func ToValues[In any, Key comparable](arr map[Key]In) []In
ToValues returns an array of just the values of the input Map.
Example ¶
nums := map[string]int{
"one": 1,
"two": 2,
"three": 3,
}
results := ToValues(nums)
sort.Ints(results) // order is not guaranteed for map keys
fmt.Println(results)
Output: [1 2 3]
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.