blob: 3c3e8e1878059e450f085b9cac24d108919d8310 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
package slices
// ContainsAll checks if slice of type E contains all elements of given slice, order independent
func ContainsAll[E comparable](haystack []E, needle []E) bool {
m := make(map[E]struct{}, len(haystack))
for _, i := range haystack {
m[i] = struct{}{}
}
for _, v := range needle {
if _, ok := m[v]; !ok {
return false
}
}
return true
}
// ContainsAllStrings checks if string slice contains all elements of given slice
// Deprecated: use ContainsAll instead
var ContainsAllStrings = ContainsAll[string]
// ContainsAllBools checks if bool slice contains all elements of given slice
// Deprecated: use ContainsAll instead
var ContainsAllBools = ContainsAll[bool]
|