more idiomatic iterator use #1145
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
NOTE: this PR is targeted at the stdlib-iterator branch as a potential improved v2 API, not current tip.
nerdsnipe alert: I'm still in relatively early phases of exploring iterator idiom, so couldn't resist having a go at simplifying SplitTokensIntoLines which is now fully streaming (even though none of the call sites look like they can take advantage of that currently).
I removed the
EOFvariable, replacing it with anIsZeromethod which can be used to check if aTokenis valid or not. (I don't see anywhere that seems to rely on yielding an EOF value: all the tests pass.)Aside: one convention from the stdlib I realise I've absorbed but never actually expressed: iterators are generally named in Go as "sequences", so perhaps use
chroma.Seqrather thanchroma.Iterator(also has the advantage that it's shorter), or just inlineiter.Seq[chroma.Token]everywhere - it's not that long and it's super-clear - and removeIteratorentirely.