Hacker News
new
|
past
|
comments
|
ask
|
show
|
jobs
|
submit
login
twic
on Aug 21, 2016
|
parent
|
context
|
favorite
| on:
What Golang Is and Is Not
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
on Aug 21, 2016
|
next
[–]
Dang, just like PHP (no built in set)
gravypod
on Aug 22, 2016
|
parent
|
next
[–]
And yet there is a generic in array function.
mappu
on Aug 22, 2016
|
root
|
parent
|
next
[–]
...which is O(n). Unless the set is trivially small, better to coerce your data to key types and use array_key_exists().
gravypod
on Aug 22, 2016
|
root
|
parent
|
next
[–]
I never said it was good, but it exists. Most of my PHP code utilizes kv arrays everywhere possible.
IshKebab
on Aug 22, 2016
|
prev
[–]
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: