I come from a Python background and so have a tendency to think in terms of iterators. It seems to me that the range
keyword in Go intends for us to think in a nearly identical way, so I would like to do somthing semantically equivalent to this Python code in Go:
for obj in json_decoder:
# business logic
Here is the motivating case in Go; consider the following function:
func (c *GorpController) Create(dec *json.Decoder) {
// business logic
}
I would like to be able to implement it as:
for someValue := range dec {
// business logic
}
Is there some sort of way to use range
with a Decoder
interface? A function that wraps it in a different interface would be ideal, and an idiomatic pattern would be acceptable.
Thank you!