delve/_fixtures/backwardsiter.go
Alessandro Arzilli def0688e7a
proc: step into coroutine (#3791)
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.
2024-09-24 10:22:04 -07:00

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()
}