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

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.


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.




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

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

Search: