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)
| 74 | // fmt.Println(Map[int](arr, addTen)) |
| 75 | // // output: [11, 12, 13] |
| 76 | func 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 | // |