Skip to content
Better HN
Top
New
Best
Ask
Show
Jobs
Search
⌘K
undefined | Better HN
story
0 points
pcwalton
9y ago
0 comments
Share
> 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.
0 comments
default
newest
oldest
twic
9y 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.
bpicolo
9y ago
Dang, just like PHP (no built in set)
gravypod
9y ago
And yet there is a generic in array function.
mappu
9y ago
...which is O(n). Unless the set is trivially small, better to coerce your data to key types and use array_key_exists().
1 more reply
IshKebab
9y ago
You can use map[X]bool as a set. Not ideal I agree, but it works ok.
j
/
k
navigate · click thread line to collapse