~/Using Zero Value Sets in Golang
Mar 15, 2019
In Go, there is no built-in set type, but you can use a map with a bool value as a set. The zero value of such a map is nil, meaning it is uninitialized but still safe for reading.
Example:
Adding items requires initialization:
Use map for simple sets. Remember that writing to or deleting from a nil map panics; only reading is safe.
If you need a custom Set type, you can wrap a map in a struct.
Check existence:
For efficient, idiomatic sets in Go, use map keys and avoid non-ASCII data in key strings to match Go best practices.