|
|
|
|
|
by cespare
4434 days ago
|
|
s := make(map[string]struct{})
s["foo"] = struct{}{}
if _, ok := s["foo"]; ok {
// exists
}
There are varying amounts of fluff you can put on top of this, but that's the basic approach. Wrap it up in a type with methods if you're using it a lot in a program.Perhaps you also want built-in union, intersection, difference, etc. I personally find I need a set with simple membership testing about 10x as often as I need more advanced set operations, so from my perspective it's fine to leave those to third-party libraries. |
|