Map transforms each element in a slice using the provided function. This is a pure function that does not modify the input slice.
(slice []T, transform func(T) U)
| 26 | // Map transforms each element in a slice using the provided function. |
| 27 | // This is a pure function that does not modify the input slice. |
| 28 | func Map[T, U any](slice []T, transform func(T) U) []U { |
| 29 | result := make([]U, len(slice)) |
| 30 | for i, item := range slice { |
| 31 | result[i] = transform(item) |
| 32 | } |
| 33 | return result |
| 34 | } |
| 35 | |
| 36 | // MapKeys converts a map's keys to a slice. |
| 37 | // The order of elements is not guaranteed as map iteration order is undefined. |
no outgoing calls