File: backwardsiter.go

package info (click to toggle)
delve 1.26.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,136 kB
  • sloc: ansic: 111,947; sh: 194; asm: 147; makefile: 43; python: 23
file content (24 lines) | stat: -rw-r--r-- 354 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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()
}