Explain the new 'Range-over-function' iterators introduced in Go 1.23.

Last updated 20 June 2026

  • Go 1.23 lets for ... range loop over functions, such as iter.Seq[V] (func(yield func(V) bool)) or iter.Seq2[K,V] for pairs.

  • The iterator calls yield once per element. If the loop breaks or returns, yield returns false and the iterator should stop.

  • This gives lazy, composable iteration over any data structure without intermediate slices. It powers the iter, slices and maps iterator helpers.

  • https://eli.thegreenplace.net/2024/ranging-over-functions-in-go-123/
  • https://appliedgo.net/go123/
All Golang interview questions