SliceTransform takes an input collection, applies the transform function to each row, and returns the output. Known as 'map' in most other languages or 'Select' in C# Linq.
(slice []T, transform func(item T) TResult)
| 46 | // SliceTransform takes an input collection, applies the transform function to each row, and returns the output. |
| 47 | // Known as 'map' in most other languages or 'Select' in C# Linq. |
| 48 | func SliceTransform[T any, TResult any](slice []T, transform func(item T) TResult) []TResult { |
| 49 | var results []TResult = nil |
| 50 | for _, item := range slice { |
| 51 | results = append(results, transform(item)) |
| 52 | } |
| 53 | return results |
| 54 | } |
| 55 | |
| 56 | // SliceFilter takes an input collection and returns elements where `predicate` returns true |
| 57 | // Known as 'filter' in most other languages or 'Select' in C# Linq. |
no outgoing calls