🌐
Go
go.dev › blog › range-functions
Range Over Function Types - The Go Programming Language
August 20, 2024 - A description of range over function types, a new feature in Go 1.23.
Discussions

Exploring Range-over Functions
This is defintiely something that is too complex to keep in my head. I'll always be googling the syntax. Being able to use range over streams and generators and having arbitrarily complex data structures that can produce a range-able iterator would be really nice though. I'm also curious what edge cases are out there that aren't immediately obvious that will get people using it in the future. They're likely to be well hidden. So I'm kind of torn. It's very useful, and a bit above the complexity threshold of the other language features. More on reddit.com
🌐 r/golang
14
19
March 13, 2024
spec: add range over int, range over func
Following discussion on #56413, I propose to add two new types that a for-range statement can range over: integers and functions. In the spec, the table that begins the section would have a few mor... More on github.com
🌐 github.com
417
July 17, 2023
go - What is "range" actually? Is it a function? - Stack Overflow
I know how range works, I've been using it multiple times. But I'm still not sure what it is behind the scene. Is it a function and a modification of range(arr)? More on stackoverflow.com
🌐 stackoverflow.com
Preview: ranging over functions in Go
“Magic! We just iterate over…” The lack of magic in go is possibly it’s best feature. More on reddit.com
🌐 r/golang
109
July 22, 2023
🌐
Go by Example
gobyexample.com › range
Go by Example: Range
range iterates over elements in a variety of data structures. Let’s see how to use range with some of the data structures we’ve already learned · Here we use range to sum the numbers in a slice. Arrays work like this too
🌐
DoltHub
dolthub.com › blog › 2024-07-12-golang-range-iters-demystified
Go range iterators demystified | DoltHub Blog
July 12, 2024 - Range iterators are function types you can use with the built-in range keyword starting in Go 1.23.
🌐
Boldly Go
boldlygo.tech › posts › 2024-07-18-range-over-func
First impressions of Go 1.23's range-over-func feature - Boldly Go
July 18, 2024 - If I can knit and crochet, surely I can loop over functions in Go! Exactly a year ago (yesterday), Russ Cox submitted a proposal to add two new range capabilities to Go: range-over-int, and range-over-func. The former was added to Go 1.22. And the latter left me immediately skeptical.
🌐
TutorialsPoint
tutorialspoint.com › go › go_range.htm
Go - Range
package main import "fmt" func main() { /* create a slice */ numbers := []int{0,1,2,3,4,5,6,7,8} /* print the numbers */ for i:= range numbers { fmt.Println("Slice item",i,"is",numbers[i]) } /* create a map*/ countryCapitalMap := map[string] string {"France":"Paris","Italy":"Rome","Japan":"Tokyo"} /* print map using keys*/ for country := range countryCapitalMap { fmt.Println("Capital of",country,"is",countryCapitalMap[country]) } /* print map using key-value*/ for country,capital := range countryCapitalMap { fmt.Println("Capital of",country,"is",capital) } }
🌐
Go
go.dev › wiki › RangefuncExperiment
Go Wiki: Rangefunc Experiment - The Go Programming Language
We clearly need to support two values to simulate existing range usages. If it were important to support three or more values, we could change those packages, but there does not appear to be a terribly strong reason to support three or more, so the simplest choice is to stop at two and leave those packages unchanged. If we find a strong reason for more in the future, we can revisit that limit. Another reason to stop at two is to have a more limited number of function ...
🌐
Reddit
reddit.com › r/golang › exploring range-over functions
r/golang on Reddit: Exploring Range-over Functions
March 13, 2024 -

I published an article about Exploring Go's experimental Function Iterators feature.

I talk about some exciting features and patterns that this feature could enable. One particular one is how it can be used to manage cleaning up resources.

Please take a read and let me know how you think this experimental feature can be helpful in your workflow

Find elsewhere
🌐
Go
go.dev › wiki › Range
Go Wiki: Range Clauses - The Go Programming Language
for k, v := range myMap { log.Printf("key=%v, value=%v", k, v) } for v := range myChannel { log.Printf("value=%v", v) } for i, v := range myArray { log.Printf("array value at [%d]=%v", i, v) }
🌐
GeeksforGeeks
geeksforgeeks.org › go language › range-keyword-in-golang
Range Keyword in Golang - GeeksforGeeks
July 12, 2025 - The range keyword is mainly used in for loops in order to iterate over all the elements of a map, slice, channel, or an array. When it iterates over the elements of an array and slices then it returns the index of the element in an integer form.
🌐
Programiz
programiz.com › golang › range
Go range (With Examples)
We use range with the for loop to iterate through the elements of array, string or map. In this tutorial, we will learn about Go for range with the help of examples.
🌐
Eli Bendersky
eli.thegreenplace.net › 2024 › ranging-over-functions-in-go-123
Ranging over functions in Go 1.23 - Eli Bendersky's website
The function parameter is named yield by convention - the name itself has no significance. yield can have 0, 1, or 2 parameters and returns a bool. The number of yield's parameters is directly mapped to the left-hand side of the for-range loop w.r.t maximal number of returned values, e.g.
🌐
GitHub
github.com › golang › go › issues › 61405
spec: add range over int, range over func · Issue #61405 · golang/go
July 17, 2023 - Following discussion on #56413, I propose to add two new types that a for-range statement can range over: integers and functions. In the spec, the table that begins the section would have a few more rows added: Range expression 1st value...
Author   rsc
🌐
GitHub
github.com › golang › go › wiki › RangefuncExperiment › 6cec221e930b7daad9c19fc67dc765ad56b7dbd5
RangefuncExperiment · golang/go Wiki · GitHub
Function iterators are normally "push" iterators where a value generator (typically a data structure visitor) "pushes" values at a function generated from the body of the loop. In some cases it is more convenient to "pull" values from the value generator, and iter.Pull accomplishes that. In this example, Zip combines two range functions into a single range function that provides the respective pairs from the two inputs:
Author   golang
🌐
Scaler
scaler.com › home › topics › golang › range loop in golang
Range Loop in Golang - Scaler Topics
May 4, 2023 - The for loop with range is used for accessing the elements of that channel and printing its values as the output. The range keyword in Golang is used with various data structures for iterating over an element.
🌐
Medium
medium.com › @shirokovroma › go-range-over-function-example-02520e462bbd
Go Range over function example. In the new Go language version 1.22.0… | by Roman Shirokov | Medium
February 20, 2024 - package main import ( "fmt" "iter" // Assuming 'iter' is the experimental package for the iterator proposal ) func IterateStrings(slice []string) iter.Seq[string] { return func(yield func(string) bool) { for _, str := range slice { if !yield(str) { break } } } } func main() { myStrings := []string{"Go", "Rangefunc", "Experiment"} // Using the iterator with the range-over-function syntax for str := range IterateStrings(myStrings) { fmt.Println(str) } } To run it: GOEXPERIMENT=rangefunc go run main.go or run with vscode · Output: Go Rangefunc Experiment · Implementation: https://go.googlesource.com/go/+/refs/changes/41/510541/7/src/cmd/compile/internal/rangefunc/rewrite.go Wiki description: https://go.dev/wiki/RangefuncExperiment · Golang ·
🌐
ZetCode
zetcode.com › golang › range
Using Range in Go
In this article we show how to iterate over data structures in Golang. The Go for range form can be used to iterate over strings, arrays, slices, maps, and channels.
🌐
Reddit
reddit.com › r/golang › preview: ranging over functions in go
r/golang on Reddit: Preview: ranging over functions in Go
July 22, 2023 - This rejects a major philosophy of Golang. Prefer readability over writability. If you want a custom map then you need to settle for the requirement of a slightly less writable iterator. Adding things that help writing but hinder reading is a mistake and shouldn’t be allowed. ... That's a pretty weak argument when the only thing preventing one from using the range keyword is simply a defined protocol (which is this proposal).
🌐
Hugo
gohugo.io › functions › go-template › range
range
February 14, 2026 - Iterates over a non-empty collection, binds context (the dot) to successive elements, and executes the block.