Map manipulates a slice and transforms it to a slice of another type.
(collection []T, mapFunc func(T) R)
| 46 | |
| 47 | // Map manipulates a slice and transforms it to a slice of another type. |
| 48 | func Map[T any, R any](collection []T, mapFunc func(T) R) []R { |
| 49 | result := make([]R, len(collection)) |
| 50 | |
| 51 | for i, item := range collection { |
| 52 | result[i] = mapFunc(item) |
| 53 | } |
| 54 | |
| 55 | return result |
| 56 | } |
| 57 | |
| 58 | // MapError manipulates a slice and transforms it to a slice of another type, |
| 59 | // returning the first error that occurred invoking the map function, if there |
no outgoing calls