range-over-functions is the experimental new feature where a function can generate a sequence by executing a bit at a time, i.e.
s := []string{"hello", "world"}
for i, x := range slices.Backward(s) {
fmt.Println(i, x)
}
func Backward[E any](s []E) func(func(int, E) bool) {
return func(yield func(int, E) bool) {
for i := len(s)-1; i >= 0; i-- {
if !yield(i, s[i]) {
return
}
}
}
}
I don't think anyone
expects this to work in Go as it is today, it's just a new feature that will make the language more complex, but it will make certain kinds of programs simpler to write.
I should also note that the official name is "range-over-function iterators", I called it by a wrong name earlier.