Initial commit of modash

This was taken from github.com/lmika/gopkgs/fp
This commit is contained in:
Leon Mika 2025-01-27 13:19:52 +11:00
commit a20530ddfd
20 changed files with 425 additions and 0 deletions

19
moslice/uniq.go Normal file
View 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
}