-
Notifications
You must be signed in to change notification settings - Fork 1
/
example_test.go
61 lines (47 loc) · 992 Bytes
/
example_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
package golist_test
import (
"fmt"
"github.com/schoukri/golist"
)
func ExampleSliceInt_Insert() {
s := golist.NewSliceInt(10, 40)
s.Insert(1, 20, 30)
for _, value := range s.Data() {
fmt.Println(value)
}
// Output:
// 10
// 20
// 30
// 40
}
func ExampleSliceInt_Count() {
s := golist.NewSliceInt(-5, 3, 2, 21, 0, 40, -4, -20, 100, 40, -9, 18, 21, -33, 40)
count := s.Filter(func(a int) bool {
return a > 10
}).Count()
uniqCount := s.Filter(func(a int) bool {
return a > 10
}).Unique().Count()
fmt.Println("total count:", count)
fmt.Println("unique count:", uniqCount)
// Output:
// total count: 7
// unique count: 4
}
func ExampleSliceInt_Transform() {
s := golist.NewSliceInt(-5, 3, 2, 21, 0, 40, -4, -20, 100, 40, -9, 18, 21, -33, 40)
s.Transform(func(a int) int {
return a * 2
}).Filter(func(a int) bool {
return a > 20
}).Unique().Sort()
for _, value := range s.Data() {
fmt.Println(value)
}
// Output:
// 36
// 42
// 80
// 200
}