forked from swxctx/gutil
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathslice.go
71 lines (64 loc) · 1.25 KB
/
slice.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
package gutil
// AddToInt add a element to slice
func AddToInt(list []int, e int) []int {
for _, l := range list {
if l == e {
return list
}
}
return append(list, e)
}
// AddToInt32 add a element to slice
func AddToInt32(list []int32, e int32) []int32 {
for _, l := range list {
if l == e {
return list
}
}
return append(list, e)
}
// AddToInt64 add a element to slice
func AddToInt64(list []int64, e int64) []int64 {
for _, l := range list {
if l == e {
return list
}
}
return append(list, e)
}
// AddToFloat32 add a element to slice
func AddToFloat32(list []float32, e float32) []float32 {
for _, l := range list {
if l == e {
return list
}
}
return append(list, e)
}
// AddToFloat64 add a element to slice
func AddToFloat64(list []float64, e float64) []float64 {
for _, l := range list {
if l == e {
return list
}
}
return append(list, e)
}
// AddToString add a element to slice
func AddToString(list []string, e string) []string {
for _, l := range list {
if l == e {
return list
}
}
return append(list, e)
}
// AddToInterface add a element to slice
func AddToInterface(list []interface{}, e interface{}) []interface{} {
for _, l := range list {
if l == e {
return list
}
}
return append(list, e)
}