6 ms·
map[T]struct{} is a type-safe set type. It's just not an ergonomic one. FWIW, I'm usually using map[T]bool and only ever inserting `true` values. It uses a bit
by majewsky 8y ago
map[T]struct{} is a type-safe set type. It's just not an ergonomic one.
FWIW, I'm usually using map[T]bool and only ever inserting `true` values. It uses a bit more space, but membership checks read like
if set[key] {
instead of
if _, ok := set[key]; ok {