MCPcopy Index your code
hub / github.com/coder/coder / Convert

Function Convert

coderd/util/slice/slice.go:241–251  ·  view source on GitHub ↗

Convert converts a slice of type F to a slice of type T using the provided function f.

(a []F, f func(F) T)

Source from the content-addressed store, hash-verified

239
240// Convert converts a slice of type F to a slice of type T using the provided function f.
241func 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
253func 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))

Callers 4

NotExistsMethod · 0.92
ExistsMethod · 0.92
OptionsMethod · 0.92

Calls

no outgoing calls