basically I have this:
package main
import "fmt"
type Struct1 struct {
id int
name string
}
type Struct2 struct {
id int
lastname string
}
type Struct3 struct {
id int
real bool
}
func main() {
var (
s1 []Struct1
s2 []Struct2
s3 []Struct3
)
s1 = append(s1, Struct1{id: 1, name: "Eliot"}, Struct1{id: 2, name: "Tyrell"}, Struct1{id: 3, name: "Mr Robot"})
s2 = append(s2, Struct2{id: 1, lastname: "Anderson"}, Struct2{id: 2, lastname: "Wellick"})
s3 = append(s3, Struct3{id: 1, real: true}, Struct3{id: 2, real: true}, Struct3{id: 3, real: false})
}
I want to show something like this:
- Eliot Anderson real(true)
- Tyrell Wellick real(true)
But I don't want to loop the s1 inside the s2 and then inside the s3
Example:
for i := 0; i < len(s1); i++ {
for j := 0; j < len(s2); j++ {
if s1[i].id == s2[j].id {
for k := 0; k < len(s3); k++ {
if s2[j].id == s3[k].id {
// some code ...
}
}
}
}
}
So, what other ways are there to doing that?