Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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 {


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: