Let's say I've got the following structs:
type A struct { Field1 string Field2 string } type B struct { Field3 string Field4 int } and one more struct which uses the previous two:
type C struct { A MyList []B } Now, I've got some data that I want to group and map into a C struct and return a slice of C:
var results []C I've got a slice of structs that looks like (since it's a slice if could happen that we have repeated A):
type X struct { A B } So I want to group the results by A. To do so I'm gonna iterate through a slice of X that my method receive as parameter:
var results []C // Y is an slice of Xs for _, elem := range Y { // If elem.A exists then append elem.B into C.A // If not then add elem.A and elem.B into C } How can achieve the stuff stated in the comments above? I mean, how could I check if a struct A exists already in the slice of structs C?