-
-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathmain.go
More file actions
52 lines (41 loc) · 685 Bytes
/
main.go
File metadata and controls
52 lines (41 loc) · 685 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"fmt"
"iter"
"time"
)
// iter.Seq[V any] func(yield func(V) bool) -- One value
// iter.Seq2[K, V any] func(yield func(K, V) bool) -- Two values: typically key-value or index-value pairs
// func(func(K, V) bool)
func Iter() func(func(int, int) bool) {
return func(yield func(int, int) bool) {
var v int
for {
if !yield(v, v+10) {
return
}
v++
}
}
}
func main() {
for i, v := range Iter() {
if i == 5 {
break
}
fmt.Println(i, v, time.Now())
}
//-
next, stop := iter.Pull2(Iter())
defer stop()
for {
i, v, ok := next()
if !ok {
break
}
if i == 5 {
break
}
fmt.Println(i, v, time.Now())
}
}