Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Map ¶
func Map(slice interface{}, fn interface{}) interface{}
Map maps the slice using the mapper function fn. Map panics if slice is not a slice, fn is not a function that accepts a single argument of the slice type or fn does not have a single return value of the slice type. The returned value is a slice with same type as the return value of fn.
Examples
names := []string{"foo", "bar", "baz"} uppercase := Map(names, strings.ToUpper).([]string) // uppercase == []string{"FOO", "BAR", "BAZ"} numbers := []int{1, 2, 4, 8} doubled := Map(numbers, func(num int) int { return num*2 }).([]int) // doubled == []int{2, 4, 8, 16}
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.