Hacker News new | ask | show | jobs
by majewsky 1990 days ago
I usually use map[T]bool because

  if _, ok := wasTouched[thing]; !ok {
    touch(thing)
    wasTouched[thing] = struct{}{}
  }
is way uglier than

  if !wasTouched[thing] {
    touch(thing)
    wasTouched[thing] = true
  }
1 comments

That doesn’t actually work unless you first fill all possible values with `false`.
Wrong. The whole point of this construct is that in Go maps return default values for keys that do not exist. The default value for bool is false.