Hacker News new | ask | show | jobs
by twic 3596 days ago
Or checking for the presence of an item in a slice. Because Go doesn't supply sets, or allow you to write them yourself, this is something i find myself needing to do a lot, and every time, i'm writing that idiotic function from scratch.
2 comments

Dang, just like PHP (no built in set)
And yet there is a generic in array function.
...which is O(n). Unless the set is trivially small, better to coerce your data to key types and use array_key_exists().
I never said it was good, but it exists. Most of my PHP code utilizes kv arrays everywhere possible.
You can use map[X]bool as a set. Not ideal I agree, but it works ok.