Okay Go, why was this omitted?
1 min readNov 23, 2022
--
When checking for the existence of a particular key in Go, the idiomatic way of doing things is this:
salary := make(map[string]uint)
.
.
.
_, ok := salary["Roger Goodell"]
if !ok {
// value wasn't found
salary["Roger Goodell"] = 68000000
} else {
fmt.Println("Roger Goodell is not hurting for cash.")
}
Simple right? Well yes, but also horribly inconvenient. I don’t want to define an in-scope variable to determine if a key exists in the map; sometimes I might want to check and quickly branch off that logic.