This feature can be implemented with 'map'.
countrySet := map[string]bool{
"US": true,
"JP": true,
"KR": true,
}
But to ease the eyes of readers, 'set' is a necessary data structure.
countrySet := set[string]{"US", "JP", "KR"}
Or init 'map' with keys only. For example:
countrySet := map[string]bool{"US", "JP", "KR"}
Does golang have the plan for supporting syntax like this?
I don't know about such plans.
What you may do to ease the initialization:
Use a one-letter bool
constant:
const t = true
countrySet := map[string]bool{"US": t, "JP": t, "KR": t}
Use a loop to add the keys, so you only need to list the keys:
countrySet := map[string]bool{}
for _, v := range []string{"US", "JP", "KR"} {
countrySet[v] = true
}
This is only profitable if you have more elements.
But you can always create a helper function:
func createSet(es ...string) map[string]bool {
m := map[string]bool{}
for _, v := range es {
m[v] = true
}
return m
}
And then using it:
countrySet := createSet("US", "JP", "KR")
The plan is not to support everything in the Go standard library. The plan is to encourage open source, independently developed packages. For example, one of many,
import "k8s.io/apimachinery/pkg/util/sets"
Package sets has auto-generated set types.