As a (then) go lang n00b, the less upvoted answers helped me e lot: [WayBack] variables – What is “_,” in a Golang declaration? – Stack Overflow:
The Go compiler won’t allow you to create variables that you never use.
for i, value := range x { total += value }The above code will return an error message “i declared and not used”.
Since we don’t use i inside of our loop we need to change it to this:
for _, value := range x { total += value }
_is the blank identifier. Meaning the value it should be assigned is discarded.Here it is the value of
examplekey that is discarded. The second line of code would discard the presence boolean and store the value inprs.
So to only check the presence in the map, you can discard the value. This can be used to use a map as a set.
–jeroen







