UPDATE: I might not have made it clear that this is just a proof-of-concept. I wanted to see if there was a clean construct that enabled iterating using range with custom behavior. I never intended to iterate over basic number sequences using this. But there might be more complex structures that need to encapsulate an iterator, and I wanted to reuse the idiomatic range iteration (instead of a Next function, or a dedicated iterator type).
This comment on Reddit gives a bit of historical context to this idea. There are performance and other issues related to this pattern, that pretty much rule it out. But I had fun learning Go by trying to make new stuff.
I guess I'm just a bit frustrated that I can't "write Go in Go". Other modern languages I've been playing with – Rust & Swift – have this idea that the standard library can be written using the language itself. And that there is no such thing as "primitive" types that would behave differently than other types. I like that, but I understand and respect Go's choice to keep the language opinionated, all the way down to the syntax.
We’re a place for programmers to stay up-to-date, learn new skills, and share ideas.
We’ll never post without your permission.