mirror of
https://github.com/coder/coder.git
synced 2025-07-08 11:39:50 +00:00
chore: refactor dynamic parameters into dedicated package (#18420)
This PR extracts dynamic parameter rendering logic from coderd/parameters.go into a new coderd/dynamicparameters package. Partly for organization and maintainability, but primarily to be reused in `wsbuilder` to be leveraged as validation.
This commit is contained in:
@ -217,3 +217,16 @@ func CountConsecutive[T comparable](needle T, haystack ...T) int {
|
||||
|
||||
return max(maxLength, curLength)
|
||||
}
|
||||
|
||||
// Convert converts a slice of type F to a slice of type T using the provided function f.
|
||||
func Convert[F any, T any](a []F, f func(F) T) []T {
|
||||
if a == nil {
|
||||
return []T{}
|
||||
}
|
||||
|
||||
tmp := make([]T, 0, len(a))
|
||||
for _, v := range a {
|
||||
tmp = append(tmp, f(v))
|
||||
}
|
||||
return tmp
|
||||
}
|
||||
|
Reference in New Issue
Block a user