Uniq returns a new slice with duplicate elements removed, preserving order.
(array []T)
| 245 | |
| 246 | // Uniq returns a new slice with duplicate elements removed, preserving order. |
| 247 | func Uniq[T comparable](array []T) []T { |
| 248 | res := make([]T, 0, len(array)) |
| 249 | seen := make(map[T]struct{}, len(array)) |
| 250 | |
| 251 | for _, e := range array { |
| 252 | if _, ok := seen[e]; ok { |
| 253 | continue |
| 254 | } |
| 255 | seen[e] = struct{}{} |
| 256 | res = append(res, e) |
| 257 | } |
| 258 | |
| 259 | return res |
| 260 | } |
no outgoing calls
no test coverage detected