The language reserves syntax for itself; you can't overload a[b] to mean anything other than either array/slice indexing or indexing into a map. You have to write methods like ".Get" or something, there's no __getattr__ or anything.
It's not just types, either. Look at the signature for the built-in sort, which is amazingly cumbersome to use. A generic wrapper around it hides all the ugly.
It’s more what you must implement along with your new data structure to make it usable in the language that was the cry of the generics advocates.
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