-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap_example_test.go
More file actions
55 lines (44 loc) · 861 Bytes
/
map_example_test.go
File metadata and controls
55 lines (44 loc) · 861 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
53
54
55
package stream_test
import (
"fmt"
"github.com/xuender/go-stream"
)
func ExampleMap() {
base1 := stream.NewBase(stream.Range2Channel(10)).
Filter(func(num int) bool { return num > 5 })
base2 := stream.Map(
base1.C,
func(num int) string { return fmt.Sprintf("[%d]", num) },
)
for num := range base2.C {
fmt.Println(num)
}
// Output:
// [6]
// [7]
// [8]
// [9]
}
func ExampleMapOrdered() {
ordered := stream.MapOrdered(
stream.Range2Channel(10),
func(num int) string { return fmt.Sprintf("[%d]", num) },
)
fmt.Println(ordered.Max())
// Output:
// [9]
}
func ExampleMapComparable() {
com := stream.MapComparable(
stream.Slice2Channel(1, 1, 1, 2, 3, 3, 4),
func(num int) string { return fmt.Sprintf("[%d]", num) },
).Distinct()
for i := range com.C {
fmt.Println(i)
}
// Output:
// [1]
// [2]
// [3]
// [4]
}