-
Notifications
You must be signed in to change notification settings - Fork 132
/
list.go
58 lines (52 loc) · 1.02 KB
/
list.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
package util
func SubtractStringList(a []string, b []string) []string {
bSet := StringListToSet(b)
result := []string{}
for _, item := range a {
if !bSet[item] {
result = append(result, item)
}
}
return result
}
func StringListToSet(list []string) map[string]bool {
set := map[string]bool{}
for _, item := range list {
set[item] = true
}
return set
}
func ContainsString(list []string, val string) bool {
for _, elem := range list {
if elem == val {
return true
}
}
return false
}
func DeepCopyListUint32(list []uint32) []uint32 {
result := make([]uint32, 0, len(list))
for _, v := range list {
result = append(result, v)
}
return result
}
func Concat[T any](slices ...[]T) []T {
total := 0
for _, s := range slices {
total += len(s)
}
result := make([]T, total)
var i int
for _, s := range slices {
i += copy(result[i:], s)
}
return result
}
func Map[T any, U any](list []T, fn func(val T) U) []U {
out := make([]U, len(list))
for i, val := range list {
out[i] = fn(val)
}
return out
}