To represent a unique set of elements in go
, use a map
.
So to create a unique set of strings from a given list, use something like:
func setFromList(list []string) (set []string) {
ks := make(map[string]bool) // map to keep track of repeats
for _, e := range list {
if _, v := ks[e]; !v {
ks[e] = true
set = append(set, e)
}
}
return
}
and to apply this to an existing gota.Series
:
func uniqueGotaSeries(s series.Series) series.Series {
return series.New(setFromList(s.Records()), s.Type(), s.Name)
}
Working playground example: https://play.golang.org/p/zqQM-0XxLF5
Output:
Orig: [b a c a d b]
Unique: [b a c d]