Answer the question
In order to leave comments, you need to log in
Set of unique values (Set) in Go?
I wondered about getting a list of parent Ids from subordinate records.
But so that it was a list of unique values.
Usually in other programming languages I use Set for this, but I did not find anything similar in Go.
But I found this solution:
uIds := make(map[string]bool)
for _, a := range articles {
uIds[strconv.Itoa(a.UserId)] = true
}
uIdsSet := make([]string, 0, len(uIds))
for k := range uIds {
uIdsSet = append(uIdsSet, k)
}
Answer the question
In order to leave comments, you need to log in
I am using AppendIfMissing
stackoverflow.com/a/9561388
But your solution is not bad either.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question