Convert converts a slice of type F to a slice of type T using the provided function f.
(a []F, f func(F) T)
| 239 | |
| 240 | // Convert converts a slice of type F to a slice of type T using the provided function f. |
| 241 | func Convert[F any, T any](a []F, f func(F) T) []T { |
| 242 | if a == nil { |
| 243 | return []T{} |
| 244 | } |
| 245 | |
| 246 | tmp := make([]T, 0, len(a)) |
| 247 | for _, v := range a { |
| 248 | tmp = append(tmp, f(v)) |
| 249 | } |
| 250 | return tmp |
| 251 | } |
| 252 | |
| 253 | func ToMapFunc[T any, K comparable, V any](a []T, cnv func(t T) (K, V)) map[K]V { |
| 254 | m := make(map[K]V, len(a)) |
no outgoing calls