package main
import ()
type Scope struct {
Type int // 1,2,3
Parent *Scope
}
func main() {
scopes := map[*Scope]string{}
filter(scopes)
}
// key is always the same type of scopes
func filter(scopes map[*Scope]string) {
// This function only works for scopes of Type 1,3
// if the Type is 2 return
// I just need to pick any item in the map to do a check
for k := range scopes {
if k.Type == 2 {
return
} else {
break
}
// Do something
}
}
I have to check the type of the key of a map. The keys of the map are of the same type. so I just need to pick any item from the map.
for k := range scopes {
if k.Type == 2 {
return
} else {
break
}
// Do something
}
this code does the check but is there a way doing this without evolving loop?