iter.Seq is Go’s generic function type for a push iterator: the iterator calls a consumer-provided yield function with each value, and the callback returns whether iteration should continue. A producer can return iter.Seq instead of a slice or channel, separating the public iteration API from its storage or execution strategy. section 6.3.1
The type supports practical iteration patterns:
- Use a for-range loop to consume values one at a time, including values produced while work is still progressing. section 6.3.1
- Let consumers gather every value or stop early, instead of requiring the producer to build a complete slice first. section 6.3.1
Testing an iterator consumer
A slice can be converted with slices.Values and passed through a domain-specific iterator type: Results(slices.Values(results)). This lets a test exercise Summarize with ordinary Result fixtures without manually implementing an iterator.
