mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
chore: Add generics to typescript generator (#4664)
* feat: Support generating generics in interfaces * Switch struct to a template * Support generics in apitypings
This commit is contained in:
@@ -22,6 +22,21 @@ func Overlap[T comparable](a []T, b []T) bool {
|
||||
})
|
||||
}
|
||||
|
||||
// Unique returns a new slice with all duplicate elements removed.
|
||||
// This is a slow function on large lists.
|
||||
// TODO: Sort elements and implement a faster search algorithm if we
|
||||
// really start to use this.
|
||||
func Unique[T comparable](a []T) []T {
|
||||
cpy := make([]T, 0, len(a))
|
||||
for _, v := range a {
|
||||
v := v
|
||||
if !Contains(cpy, v) {
|
||||
cpy = append(cpy, v)
|
||||
}
|
||||
}
|
||||
return cpy
|
||||
}
|
||||
|
||||
func OverlapCompare[T any](a []T, b []T, equal func(a, b T) bool) bool {
|
||||
// For each element in b, if at least 1 is contained in 'a',
|
||||
// return true.
|
||||
|
||||
Reference in New Issue
Block a user