...
1
2
3
4
5 package p
6
7
8
9
10 func f1[K1 comparable, E1 any](m1 map[K1]E1) {}
11
12 func f2[M2 map[string]int](m2 M2) {
13 f1(m2)
14 }
15
16
17
18
19 type Map3 map[string]int
20
21 func f3[M3 Map3](m3 M3) {
22 f1(m3)
23 }
24
25
26
27 func f4[M4 map[K4]int, K4 comparable](m4 M4) {}
28
29 func f5[M5 map[K5]int, K5 comparable](m5 M5) {
30 f4(m5)
31 }
32
33
34
35 func Copy[MC ~map[KC]VC, KC comparable, VC any](dst, src MC) {
36 for k, v := range src {
37 dst[k] = v
38 }
39 }
40
41 func Merge[MM ~map[KM]VM, KM comparable, VM any](ms ...MM) MM {
42 result := MM{}
43 for _, m := range ms {
44 Copy(result, m)
45 }
46 return result
47 }
48
View as plain text