sliceutil.go 328 B

1234567891011
  1. package sliceutil
  2. // Map accepts a slice of T and applies a transformation function to each index of a
  3. // slice, which are inserted into a new slice of type U.
  4. func Map[T any, U any](s []T, transform func(T) U) []U {
  5. result := make([]U, len(s))
  6. for i := 0; i < len(s); i++ {
  7. result[i] = transform(s[i])
  8. }
  9. return result
  10. }