Unique returns a new slice with all duplicate elements removed.
(a []T)
| 143 | |
| 144 | // Unique returns a new slice with all duplicate elements removed. |
| 145 | func 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 | |
| 161 | func 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', |
no outgoing calls