-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample_test.go
More file actions
90 lines (71 loc) · 1.6 KB
/
example_test.go
File metadata and controls
90 lines (71 loc) · 1.6 KB
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
88
89
90
// SPDX-FileCopyrightText: 2020-2024 caixw
//
// SPDX-License-Identifier: MIT
package sliceutil
import "fmt"
func ExampleAt() {
intSlice := []int{1, 2, 3, 7, 0, 4, 7}
v, found := At(intSlice, func(e, _ int) bool {
return e == 7
})
fmt.Println(found, v)
// Output: true 7
}
func ExampleIndex() {
intSlice := []int{1, 2, 3, 7, 0, 4, 7}
fmt.Println(Index(intSlice, func(e, _ int) bool {
return e == 7
}))
// Output: 3
}
func ExampleExists() {
intSlice := []int{1, 2, 3, 7, 0, 4, 7}
fmt.Println(Exists(intSlice, func(e, _ int) bool {
return e == 7
}))
// Output: true
}
func ExampleDup() {
intSlice := []int{1, 2, 3, 7, 0, 4, 7}
fmt.Println(Dup(intSlice, func(i, j int) bool {
return i == j
}))
// Output: [3 6]
}
func ExampleCount() {
intSlice := []int{1, 2, 3, 7, 0, 4, 7}
fmt.Println(Count(intSlice, func(e, _ int) bool {
return e == 7
}))
// Output: 2
}
func ExampleDelete() {
intSlice := []int{1, 2, 3, 7, 0, 4, 7}
rslt := Delete(intSlice, func(e, _ int) bool {
return e == 7
})
fmt.Println("Delete:", rslt)
intSlice = []int{1, 2, 3, 7, 0, 4, 7}
rslt = QuickDelete(intSlice, func(e, _ int) bool {
return e == 7 || e == 2
})
fmt.Println("QuickDelete:", rslt)
// Output: Delete: [1 2 3 0 4]
// QuickDelete: [1 4 3 0]
}
func ExampleUnique() {
intSlice := []int{1, 2, 3, 7, 0, 4, 7}
rslt := Unique(intSlice, func(i, j int) bool {
return i == j
})
fmt.Println(rslt)
// Output: [1 2 3 7 0 4]
}
func ExampleContains() {
ints1 := []int{1, 2, 3, 4, 5}
ints2 := []int{1, 5, 2}
fmt.Println(Contains(ints1, ints2, func(i, j int) bool {
return i == j
}))
// Output: true
}