Y
Hacker News
new
|
ask
|
show
|
jobs
by
pcwalton
3596 days ago
> The Go standard library is full of things that do exactly what you want them to, whereas in other languages you have to manually do it yourself.
Sorting a slice is a pretty obvious counterexample.
1 comments
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.
link
bpicolo
3596 days ago
Dang, just like PHP (no built in set)
link
gravypod
3595 days ago
And yet there is a generic in array function.
link
mappu
3595 days ago
...which is O(n). Unless the set is trivially small, better to coerce your data to key types and use array_key_exists().
link
gravypod
3595 days ago
I never said it was good, but it exists. Most of my PHP code utilizes kv arrays everywhere possible.
link
IshKebab
3595 days ago
You can use map[X]bool as a set. Not ideal I agree, but it works ok.
link