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

Function Unique

coderd/util/slice/slice.go:145–159  ·  view source on GitHub ↗

Unique returns a new slice with all duplicate elements removed.

(a []T)

Source from the content-addressed store, hash-verified

143
144// Unique returns a new slice with all duplicate elements removed.
145func Unique[T comparable](a []T) []T {
146 cpy := make([]T, 0, len(a))
147 seen := make(map[T]struct{}, len(a))
148
149 for _, v := range a {
150 if _, ok := seen[v]; ok {
151 continue
152 }
153
154 seen[v] = struct{}{}
155 cpy = append(cpy, v)
156 }
157
158 return cpy
159}
160
161func OverlapCompare[T any](a []T, b []T, equal func(a, b T) bool) bool {
162 // For each element in b, if at least 1 is contained in 'a',

Callers 12

RunMethod · 0.92
ApplyGroupDifferenceMethod · 0.92
SyncRolesMethod · 0.92
syncSiteWideRolesMethod · 0.92
SyncOrganizationsMethod · 0.92
ParseClaimsMethod · 0.92
TestOIDCClaimsFunction · 0.92
ReportAppStatsMethod · 0.92
TestUniqueFunction · 0.92
newProvisionerDaemonFunction · 0.92
ParseRoleClaimsMethod · 0.92

Calls

no outgoing calls

Tested by 2

TestOIDCClaimsFunction · 0.74
TestUniqueFunction · 0.74