...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package slice
16
17 import "sort"
18
19 func StringSliceContains(l []string, s string) bool {
20 for _, elem := range l {
21 if elem == s {
22 return true
23 }
24 }
25 return false
26 }
27
28
29
30 func IncludeString(l []string, s string) []string {
31 i := sort.Search(
32 len(l),
33 func(i int) bool {
34 return l[i] >= s
35 },
36 )
37 if i < len(l) && l[i] == s {
38
39 return l
40 }
41 l = append(l, "")
42 copy(l[i+1:], l[i:])
43 l[i] = s
44 return l
45 }
46
47 func RemoveStringFromStringSlice(l []string, s string) []string {
48 newSlice := make([]string, 0)
49 for _, elem := range l {
50 if elem != s {
51 newSlice = append(newSlice, elem)
52 }
53 }
54 return newSlice
55 }
56
57 func ConcatStringSlices(slices ...[]string) []string {
58 newSlice := make([]string, 0)
59 for _, s := range slices {
60 newSlice = append(newSlice, s...)
61 }
62 return newSlice
63 }
64
65
66
67
68 func IsListOfStringInterfaceMaps(list []interface{}) bool {
69 if len(list) == 0 {
70 return false
71 }
72 for _, e := range list {
73 _, ok := e.(map[string]interface{})
74 if !ok {
75 return false
76 }
77 }
78 return true
79 }
80
81 func Reverse(slice []string) {
82 length := len(slice)
83 midIndex := length / 2
84
85 for i := 0; i < midIndex; i++ {
86 j := length - i - 1
87
88 slice[i], slice[j] = slice[j], slice[i]
89 }
90 }
91
View as plain text