2026-08-092 min read

iter.Seq2: A Very Go Name

Go’s new iterator API is, in most respects, nicely designed. And then there is: iter.Seq2

GoProgramming Languages

Go’s iterator API is small and regular:

iter.Seq[V]
iter.Seq2[K, V]

Seq yields one value. Seq2 yields two.

The naming is technically precise, but Seq2 is a little unusual for a public Go API. The name describes the arity of the iterator rather than the role of the values it produces.

In many common cases, those two values are naturally key and value:

for k, v := range m {
    ...
}

For slices, the same pattern is index and value, which is close enough to the same model that a name such as SeqKV[K, V] would not be surprising.

It could even have been an alias:

type SeqKV[K, V any] = Seq2[K, V]

That would leave Seq2 available for cases where the two values have no key/value interpretation, while giving collection-oriented APIs a slightly more descriptive type name.

Go generally avoids this kind of synonym. One concept having one name keeps the API smaller, documentation simpler, and conventions easier to establish.

Ruby would likely make a different tradeoff. Its standard library is comfortable with names such as map and collect, or find and detect, where two names serve essentially the same operation.

They simply optimize for different things.

In Go, the result is Seq2: short, general, and very Go.