-
Notifications
You must be signed in to change notification settings - Fork 0
/
genericMap.go
56 lines (43 loc) · 949 Bytes
/
genericMap.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
package main
//////////////////////
// LOL YES GENERICS //
//////////////////////
var member struct{}
type Map[K comparable, V any] map[K]V
type theme_info Map[string, string]
type set Map[string, struct{}]
// generic methods, kinda
func (c theme_info) Map() Map[string, string] {
return Map[string, string](c)
}
func (s set) Map() Map[string, struct{}] {
return Map[string, struct{}](s)
}
func (m Map[K, V]) contains_key(key K) bool {
for k := range m {
if k == key {
return true
}
}
return false
}
func (m Map[K, V]) contains_at_least_one_key(keys set) bool {
for key := range m {
if m.contains_key(key) {
return true
}
}
return false
}
func (m Map[K, V]) contains_all_keys(keys []K) (bool, []K) {
var not_contained []K
for _, key := range keys {
if !m.contains_key(key) {
not_contained = append(not_contained, key)
}
}
if len(not_contained) > 0 {
return false, not_contained
}
return true, nil
}