Initial commit of modash
This was taken from github.com/lmika/gopkgs/fp
This commit is contained in:
commit
a20530ddfd
20 changed files with 425 additions and 0 deletions
19
moslice/uniq.go
Normal file
19
moslice/uniq.go
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
package moslice
|
||||
|
||||
func Uniq[T comparable](ts []T) []T {
|
||||
if len(ts) < 2 {
|
||||
return ts
|
||||
}
|
||||
|
||||
outT := make([]T, 0)
|
||||
seenT := make(map[T]struct{})
|
||||
|
||||
for _, t := range ts {
|
||||
if _, ok := seenT[t]; !ok {
|
||||
outT = append(outT, t)
|
||||
seenT[t] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
return outT
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue