
The step command is changed such that when the function being currently called is a coroutine switch function it will move to the associated coroutine. Functions that switch coroutines are currently the next, stop and yield closures produced by the iter.Pull function.
25 lines
354 B
Go
25 lines
354 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"iter"
|
|
)
|
|
|
|
func backwards(s []int) func(func(int) bool) {
|
|
return func(yield func(int) bool) {
|
|
for i := len(s) - 1; i >= 0; i-- {
|
|
if !yield(s[i]) {
|
|
break
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
func main() {
|
|
next, stop := iter.Pull(backwards([]int{10, 20, 30, 40}))
|
|
fmt.Println(next())
|
|
fmt.Println(next())
|
|
fmt.Println(next())
|
|
stop()
|
|
}
|