-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslices_test.go
87 lines (67 loc) · 1.81 KB
/
slices_test.go
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package tl_test
import (
"fmt"
"strconv"
"strings"
"github.com/dgrr/tl"
)
func ExampleMap() {
numbers := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
numbersToString := tl.Map(numbers, func(number int) string {
return strconv.Itoa(number)
})
fmt.Println(numbers)
fmt.Println(numbersToString)
}
func ExampleFilter() {
filterThis := []string{
"Each type parameter has a type",
"constraint that acts as a kind of",
"meta-type for the type parameter",
"Each type constraint specifies the permissible",
"type arguments that calling",
"code can use for the respective",
"type parameter",
}
// filter out the strings containing `type`.
afterFilter := tl.Filter(filterThis, func(x string) bool {
return !strings.Contains(x, "type")
})
fmt.Println(strings.Join(filterThis, "\n"))
fmt.Println("--- after ----")
fmt.Println(strings.Join(afterFilter, "\n"))
}
func ExampleFilterInPlace() {
filterThis := []string{
"Each type parameter has a type",
"constraint that acts as a kind of",
"meta-type for the type parameter",
"Each type constraint specifies the permissible",
"type arguments that calling",
"code can use for the respective",
"type parameter",
}
// filter out the strings containing `type`.
filterThis = tl.FilterInPlace(filterThis, func(x string) bool {
return !strings.Contains(x, "type")
})
fmt.Println(strings.Join(filterThis, "\n"))
}
func ExampleJoin() {
a := []int{1, 2, 3, 4, 5, 6, 7, 8}
b := []int{5, 7, 9, 11, 13}
joined := tl.Join(a, b)
fmt.Println("All", joined)
}
func ExampleAntiJoin() {
a := []int{1, 2, 3, 4, 5, 6, 7, 8}
b := []int{5, 7, 9, 11, 13}
antijoined := tl.AntiJoin(a, b)
fmt.Println("All", antijoined)
}
func ExampleMerge() {
a := []int{1, 2, 3, 4, 5, 6, 7, 8}
b := []int{5, 7, 9, 11, 13}
merged := tl.Merge(a, b)
fmt.Println("All", merged)
}