We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 1cbe142 commit fa8dd60Copy full SHA for fa8dd60
map.go
@@ -0,0 +1,36 @@
1
+package handy
2
+
3
+func NewMap[TK comparable, TV any]() *Map[TK, TV] {
4
+ return &Map[TK, TV]{
5
+ m: make(map[TK]TV),
6
+ }
7
+}
8
9
+type Map[TK comparable, TV any] struct {
10
+ m map[TK]TV
11
12
13
+func (m *Map[TK, TV]) HasKey(key TK) bool {
14
+ _, ok := m.m[key]
15
+ return ok
16
17
18
+func (m *Map[TK, TV]) Set(key TK, value TV) {
19
+ m.m[key] = value
20
21
22
+func (m *Map[TK, TV]) SetOnce(key TK, value TV) bool {
23
+ if _, ok := m.m[key]; !ok {
24
25
+ return true
26
27
+ return false
28
29
30
+func (m *Map[TK, TV]) Merge(maps ...*Map[TK, TV]) {
31
+ for _, each := range maps {
32
+ for k, v := range each.m {
33
+ m.m[k] = v
34
35
36
0 commit comments