Menu

1 / 2

iter.Seq in Go 1.23+: The Iterator Type Behind range-over-func

DEV Community·Gabriel Anhaia·6 months ago
#nycoDpuS
#go#programming#backend#tutorial#iter
Reading 0:00
15s threshold

Book: The Complete Guide to Go Programming

Also by me: Thinking in Go (2-book series) — Complete Guide to Go Programming + Hexagonal Architecture in Go

My project: Hermes IDE | GitHub — an IDE for developers who ship with Claude Code and other AI coding tools

Me: xgabriel.com | GitHub

Range-over-func is the language feature everyone wrote about in Go 1.23. iter.Seq[V] is the type your code is supposed to pass around. The standard library quietly grew an ecosystem to feed it, drain it, sort it, and chunk it.

The whole iter package fits on one screen — two type aliases and two helpers :

package iter

type Seq [ V any ] func ( yield func ( V ) bool ) type Seq2 [ K , V any ] func ( yield func ( K , V ) bool )

func Pull [ V any ]( seq Seq [ V ]) ( next func () ( V , bool ), stop func ()) func Pull2 [ K , V any ]( seq Seq2 [ K , V ]) ( next func () ( K , V , bool ), stop func ())

Enter fullscreen mode

Exit fullscreen mode

Two type aliases for callback-shaped functions and two helpers that flip from push…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.