I'm not sure what you mean. The `yield` function does exactly the same as Python's `yield` statement and in fact, that's part of why the name was chosen.
Compare Python:
def vals(a):
for v in a:
yield v
for x in vals([1,2,3]):
print(x)
With Go:
func vals[T any](s []T) iter.Seq[T] {
return func(yield func(T) bool) {
for _, v := range s {
if !yield(v) { return }
}
}
}
func main() {
for v := range vals([]int{1,2,3}) {
fmt.Println(v)
}
}
Sure, there is a little bit more ceremony involved, as you need things to be typed and need to return a closure. But ultimately, the generating function (in Go, the closure) calls yield to… yield a value.