-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtake_example_test.go
More file actions
47 lines (41 loc) · 977 Bytes
/
take_example_test.go
File metadata and controls
47 lines (41 loc) · 977 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
package itu_test
import (
"fmt"
"slices"
"github.com/lymar/itu"
)
func ExampleTake() {
seq := slices.Values([]int{10, 11, 12, 13, 14, 15})
fmt.Println(slices.Collect(itu.Take(seq, 3)))
// Output:
// [10 11 12]
}
func ExampleTake2() {
// slices.All returns an iter.Seq2 over index/value pairs.
all := slices.All([]string{"a", "b", "c"})
seq := itu.Take2(all, 2)
for i, v := range seq {
fmt.Printf("%d:%s\n", i, v)
}
// Output:
// 0:a
// 1:b
}
func ExampleTakeWhile() {
seq := slices.Values([]int{10, 11, 12, 13, 14, 15})
out := slices.Collect(itu.TakeWhile(seq, func(v int) bool { return v <= 12 }))
fmt.Println(out)
// Output:
// [10 11 12]
}
func ExampleTakeWhile2() {
// slices.All returns an iter.Seq2 over index/value pairs.
all := slices.All([]string{"a", "b", "stop", "c"})
seq := itu.TakeWhile2(all, func(_ int, v string) bool { return v != "stop" })
for i, v := range seq {
fmt.Printf("%d:%s\n", i, v)
}
// Output:
// 0:a
// 1:b
}