Map applies the function f to each element of the slice and returns a new slice containing the results.
(s []T, f func(T) R)
| 3 | |
| 4 | // Map applies the function f to each element of the slice and returns a new slice containing the results. |
| 5 | func Map[T, R any](s []T, f func(T) R) []R { |
| 6 | r := make([]R, 0, len(s)) |
| 7 | for _, v := range s { |
| 8 | r = append(r, f(v)) |
| 9 | } |
| 10 | return r |
| 11 | } |
| 12 | |
| 13 | // Filter returns a new slice containing all elements of the slice that satisfy the predicate function. |
| 14 | func Filter[T any](s []T, f func(T) bool) []T { |
no outgoing calls