-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
63 lines (51 loc) · 1.09 KB
/
utils.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
package goconcat
// removes index and returns new slice
func removeFromSlice[T any](slice []T, index int) (poppedSlice []T) {
for i, s := range slice {
if i == index {
continue
}
poppedSlice = append(poppedSlice, s)
}
return
}
// return index from slice
func popFromSlice[T any](slice []T, index int) (singleElement T) {
for i, s := range slice {
if index == i {
singleElement = s
}
}
return
}
// return index from slice
func returnAllButIndices[T any](slices []T, indices []int) (newSlice []T) {
ignoredIndex := make(map[int]int)
// map slice of ints
for _, num := range indices {
ignoredIndex[num] = num
}
for index, slice := range slices {
if _, ok := ignoredIndex[index]; ok {
continue
}
newSlice = append(newSlice, slice)
}
return
}
type stringConvert interface {
~string
}
func anyToString[T stringConvert](s T) string {
return string(s)
}
type tSlice interface {
~string
}
func stringToType[T tSlice](slice []string) []T {
var newDirectories []T
for _, s := range slice {
newDirectories = append(newDirectories, T(s))
}
return newDirectories
}