Re:Go and Simplicity Debt Redux
by majewsky on Monday June 19, 2017 @06:21AM
(#14585795)
The difference in behavior between the one-return-value and the two-return-value version is that the former returns a zero value when the key does not exist in the collection. The one-return-value version is only there, basically, because you can use its return value inside an expression, whereas multiple return values have to be unpacked into variables first (unless you `return` them directly).
If Go had generics, the overloads could be merged into a single operator[] that returns a Maybe<ValueType>. Then that Maybe type would have an Or() method to supply a default, e.g.
If Go had generics, the overloads could be merged into a single operator[] that returns a Maybe<ValueType>. Then that Maybe type would have an Or() method to supply a default, e.g.