In fact I created a struct that you can range over just a couple of days ago.
I can’t say I love the way Go implemented it though. But it does work.
Why not?
1. How it should be implemented “correctly”
2. The resulting code isn’t clear how it works at first glance (particularly with the yield command, it has “magical” properties that take a little effort to grok)
3. Requires calling a method
Example code: https://github.com/lmorg/Ttyphoon/blob/321738f289e4791e9674d...
I did write this at something like 11pm so it’s entirely possible I’ve done this completely wrong though.
Also please ignore the weird use of mutexes here too.
I’m also aware that sync.Map could/should have been used here. This struct was more of an experiment than anything that will ultimately find its way into production code.
But I suspect they meant a struct which contains/encapsulates data which can be ranged over.
EDIT: Had to check, yeah I had to implement the iter.Seq type to do it