File tree Expand file tree Collapse file tree 1 file changed +58
-0
lines changed Expand file tree Collapse file tree 1 file changed +58
-0
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ package maps_test
7
7
import (
8
8
"fmt"
9
9
"maps"
10
+ "slices"
10
11
"strings"
11
12
)
12
13
@@ -133,3 +134,60 @@ func ExampleEqualFunc() {
133
134
// Output:
134
135
// true
135
136
}
137
+
138
+ func ExampleAll () {
139
+ m1 := map [string ]int {
140
+ "one" : 1 ,
141
+ "two" : 2 ,
142
+ }
143
+ m2 := map [string ]int {
144
+ "one" : 10 ,
145
+ }
146
+ maps .Insert (m2 , maps .All (m1 ))
147
+ fmt .Println ("m2 is:" , m2 )
148
+ // Output:
149
+ // m2 is: map[one:1 two:2]
150
+ }
151
+
152
+ func ExampleKeys () {
153
+ m1 := map [int ]string {
154
+ 1 : "one" ,
155
+ 10 : "Ten" ,
156
+ 1000 : "THOUSAND" ,
157
+ }
158
+ keys := slices .Sorted (maps .Keys (m1 ))
159
+ fmt .Println (keys )
160
+ // Output:
161
+ // [1 10 1000]
162
+ }
163
+
164
+ func ExampleValues () {
165
+ m1 := map [int ]string {
166
+ 1 : "one" ,
167
+ 10 : "Ten" ,
168
+ 1000 : "THOUSAND" ,
169
+ }
170
+ keys := slices .Sorted (maps .Values (m1 ))
171
+ fmt .Println (keys )
172
+ // Output:
173
+ // [THOUSAND Ten one]
174
+ }
175
+
176
+ func ExampleInsert () {
177
+ m1 := map [int ]string {
178
+ 1000 : "THOUSAND" ,
179
+ }
180
+ s1 := []string {"zero" , "one" , "two" , "three" }
181
+ maps .Insert (m1 , slices .All (s1 ))
182
+ fmt .Println ("m1 is:" , m1 )
183
+ // Output:
184
+ // m1 is: map[0:zero 1:one 2:two 3:three 1000:THOUSAND]
185
+ }
186
+
187
+ func ExampleCollect () {
188
+ s1 := []string {"zero" , "one" , "two" , "three" }
189
+ m1 := maps .Collect (slices .All (s1 ))
190
+ fmt .Println ("m1 is:" , m1 )
191
+ // Output:
192
+ // m1 is: map[0:zero 1:one 2:two 3:three]
193
+ }
You can’t perform that action at this time.
0 commit comments