I was building a little Go package that iterates over some structure,
internally just a []*Thing.
In the old days in Go, as I've done in several languages
even when they had iterators, I'd have done something like
an Each function that takes a function f (actual could be closure) that it applies
to each thing. It's a few lines of code to write, almost without thinking, and I quickly
know what it does, how it works and what it costs.
Still, sitting here tonight, isn't this now supposed to be an iterator?
Then users can do for ... range ... instead of calling Each(func(...)...) to (say) find the thing.
On looking at the existing docs, I felt I was quickly heading into a world of pain, which I really have never found with Go (there were things I disliked but I was wrong and recanted years ago). I googled about the pain and as often happens I was not the only one:
hits quite a few of the things that occurred to me and hints at the need for something
to say what to do.
Is there a good summary of what to do? Normally now I use grok but this is Go and
I'm hoping I don't need to be an LLM to make sense of it.
(Aside: In an Ada app I replaced the use of Ada's standard library hash-map packages by the few dozen lines of code to implement a straightforward hash-map, because I discovered the generic Ada one generated something like 60,000 lines of machine instruction, many of which were there to provide bookmarking of open iterators to be able to invalidate them if something changed. I don't know whether Go tries to do that.)