TIL: Streaming Data in Go with iter and yield
While building RagPack, a library that chunks files for embedding, I needed a common way to stream parsed content from multiple file formats. RagPack supports CSV, PDF, DOCX, HTML, XLSX, Markdown, JSON and more. Each format has its own parser, but the ingester that consumes them should not care which one it is talking to. I needed a shared contract. In Java I would have reached for an Iterator<T> or an InputStream, but in Go the answer turned out to be the iter package, introduced in Go 1.23.
The Parser interface
The iter package introduces two types. Seq[V] yields a single value at a time, and Seq2[K, V] yields a pair:
type Seq[V any] func(yield func(V) bool)






