Implement top shares page
This commit is contained in:
14
notlinq/notlinq.go
Normal file
14
notlinq/notlinq.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package notlinq
|
||||
|
||||
func UniqueBy[T any, K comparable](items []T, keySelector func(T) K) []T {
|
||||
seen := make(map[K]struct{})
|
||||
result := make([]T, 0, len(items))
|
||||
for _, item := range items {
|
||||
key := keySelector(item)
|
||||
if _, exists := seen[key]; !exists {
|
||||
seen[key] = struct{}{}
|
||||
result = append(result, item)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
Reference in New Issue
Block a user