MCPcopy Index your code
hub / github.com/adam-hanna/arrayOperations / Map

Function Map

arrayOperations.go:76–84  ·  view source on GitHub ↗

Map iterates through an array applying the transform function to each element and returns the modified array arr := []int{1,2,3} func addTen(i int) int { return i + 10 } fmt.Println(Map[int](arr, addTen)) // output: [11, 12, 13]

(arr []T, transform func(T) T)

Source from the content-addressed store, hash-verified

74// fmt.Println(Map[int](arr, addTen))
75// // output: [11, 12, 13]
76func Map[T any](arr []T, transform func(T) T) []T {
77 ret := make([]T, len(arr))
78
79 for idx := range arr {
80 ret[idx] = transform(arr[idx])
81 }
82
83 return ret
84}
85
86// Distinct returns the unique vals of a slice
87//

Callers 1

TestMapFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestMapFunction · 0.68