---
source: https://iinventedlight.com/library/notes/go-range-over-func.md
title: "Range over function iterators in Go 1.23"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "CC BY 4.0 (go.dev text); prose restates cited source lines"
attribution: "Summary by iinventedlight (AI-assisted). Sources: The Go Authors (go.dev), Range Over Function Types - The Go Programming Language, CC BY 4.0 (go.dev text); The Go Authors (go.dev), The Go Programming Language Specification - The Go Programming Language, CC BY 4.0 (go.dev text)."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-04
status: published
checked_on: 2026-11-04
as_of: 2026-11-04
confidence: medium
untested: "No code was run for this note; only the fetched documentation pages were read."
category: coding-references
topic_area: "code-ai-eng: Go"
tags: ['go', 'iterators', 'generics', 'range']
sources:
  - id: S1
    title: "Range Over Function Types - The Go Programming Language"
    publisher: The Go Authors (go.dev)
    url: https://go.dev/blog/range-functions
    accessed: 2026-11-04
    license: "CC BY 4.0 (go.dev text)"
  - id: S2
    title: "The Go Programming Language Specification - The Go Programming Language"
    publisher: The Go Authors (go.dev)
    url: https://go.dev/ref/spec
    accessed: 2026-11-04
    license: "CC BY 4.0 (go.dev text)"
---
# Range over function iterators in Go 1.23

**Answer:** Since Go 1.23, a `for ... range` loop can range over a function. An iterator is a function that takes a `yield` callback; it calls `yield` for each value and stops if `yield` returns false.

## Shapes

```go
func(yield func() bool)
func(yield func(V) bool)
func(yield func(K, V) bool)
```

## Example

```go
func Count(n int) iter.Seq[int] {
    return func(yield func(int) bool) {
        for i := 0; i < n; i++ {
            if !yield(i) { return }
        }
    }
}

for i := range Count(3) { fmt.Println(i) }
```

When the loop body hits `break`, `yield` returns false and the iterator should stop.

## Claims
- id: C1
  claim: Range over function types is new in Go 1.23.
  source: S1
  evidence: "Range over function types is a new language feature in the Go 1.23"
- id: C2
  claim: By convention the callback is called yield.
  source: S1
  evidence: "arguments and returns a bool; by convention, we call it the yield"
- id: C3
  claim: Go 1.23 supports ranging over functions.
  source: S1
  evidence: "As of Go 1.23 it now supports ranging over functions that take a"
- id: C4
  claim: The spec lists func(yield func(V) bool) as a range form.
  source: S2
  evidence: "func(yield func(V) bool)"

## Sources
- [S1] Range Over Function Types - The Go Programming Language. The Go Authors (go.dev). https://go.dev/blog/range-functions . License: CC BY 4.0 (go.dev text). Accessed 2026-11-04.
- [S2] The Go Programming Language Specification - The Go Programming Language. The Go Authors (go.dev). https://go.dev/ref/spec . License: CC BY 4.0 (go.dev text). Accessed 2026-11-04.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted).
