---
source: https://iinventedlight.com/library/notes/go-iter.md
title: "Go iter: Seq, Seq2, and pull-style iterators over sequences"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "BSD-3-Clause (The Go Authors); BSD-3-Clause (The Go Authors); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: The Go Authors, iter package; The Go Authors, iter.go (source). BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-27
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-27
as_of: 2026-11-27
confidence: medium
untested: "Not reproduced (2026-11-27). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-systems: go-iter"
tags: [go, iter, seq, pull, range]
client: Librarian
sources:
  - id: S1
    title: "iter package"
    publisher: The Go Authors
    url: https://pkg.go.dev/iter
    accessed: 2026-11-27
    license: "BSD-3-Clause"
  - id: S2
    title: "iter.go (source)"
    publisher: The Go Authors
    url: https://go.dev/src/iter/iter.go
    accessed: 2026-11-27
    license: "BSD-3-Clause"
---
# Go iter: Seq, Seq2, and pull-style iterators over sequences
**Answer:** The iter package provides basic definitions and operations for iterators over sequences.

## Push iterators: Seq and Seq2

An iterator hands successive sequence elements to a callback, conventionally named yield.

Iteration stops when the sequence is finished, or when yield returns false to request an early stop.

Seq and Seq2 are pronounced like seek, the first syllable of sequence. They pass one or two values per element to yield.

Seq2 is for paired values, usually key-value or index-value pairs.

Yield returns true to continue and false to stop. Calling it again after a false return panics.

Iterator functions are most often driven by a range loop.

On a collection type, that method is conventionally named All, because it walks every value in the collection.

Single-use iterators typically report values from a data stream that cannot be rewound. Functions that return them should document that fact.

## Pull, standard library use, and mutation

Pull converts a push-style Seq into a pull-style iterator accessed through next and stop.

Next returns the next value and a boolean saying whether it is valid. After the sequence ends, next returns the zero value and false.

Stop ends the iteration. Call it when you no longer want next values and next has not yet signaled the end. Callers typically defer stop(). Using next or stop from multiple goroutines at once is an error.

Pull2 likewise converts a Seq2 push iterator into a pull iterator accessed by next and stop.

A few standard library packages expose iterator APIs, notably maps and slices, such as maps.Keys and slices.Sorted.

Iterators provide only the values of the sequence, not a direct way to modify it. To allow modification during iteration, define a position type.

## See also

- [go-slices](https://iinventedlight.com/library/notes/go-slices/)
- [go-maps](https://iinventedlight.com/library/notes/go-maps/)
- [go-range-over-func](https://iinventedlight.com/library/notes/go-range-over-func/)

## Claims

- id: C1
  claim: An iterator passes successive sequence elements to a callback named yield.
  source: S1
  evidence: "An iterator is a function that passes successive elements of a"

- id: C2
  claim: Seq and Seq2 are pronounced like seek, the first syllable of sequence.
  source: S2
  evidence: "pronounced like seek—the first syllable of sequence"

- id: C3
  claim: Pull turns a push-style Seq into next and stop functions.
  source: S1
  evidence: "Pull converts the “push-style” iterator sequence seq"

## Sources

- [S1] iter package. The Go Authors. https://pkg.go.dev/iter . License: BSD-3-Clause. Accessed 2026-11-27.

- [S2] iter.go (source). The Go Authors. https://go.dev/src/iter/iter.go . License: BSD-3-Clause. Accessed 2026-11-27.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: The Go Authors, iter package; The Go Authors, iter.go (source). BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors. Text was condensed and changed from the originals.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
