@@ -12,6 +12,19 @@ C<Hash> implements C<Associative> through its inheritance of C<Map> and as such
12
12
provides support for looking up values using keys, providing support for
13
13
L < associative subscripting|/language/subscripts#Methods_to_implement_for_associative_subscripting > .
14
14
15
+ Although the order of the hashes is guaranteed to be random in every single
16
+ call, still successive calls to C < .keys > and C < .values > are guaranteed to return
17
+ them in the same order:
18
+
19
+ my %orig = :1a, :2b; my %new = :5b, :6c;
20
+ %orig{ %new.keys } = %new.values;
21
+ say %orig.perl; # OUTPUT: «{:a(1), :b(5), :c(6)}»
22
+
23
+ In this case, C < b > will always be associated to 5 and C < c > to 6; even if two
24
+ succesive calls to C < keys > will return them in different order. Successive calls
25
+ to any of them separately and repeatedly will always return the same order in
26
+ any program invocation.
27
+
15
28
= head1 Methods
16
29
17
30
= head2 method classify-list
@@ -35,7 +48,7 @@ value respectively. A L«C<Callable>|/type/Callable» mapper will be executed
35
48
once per each item in the C < @list > , with that item as the argument and its
36
49
return value will be used as the mapper's value.
37
50
38
- = head3 Simple Classification
51
+ = head3 Simple classification
39
52
40
53
In simple classification mode, each mapper's value is any non-Iterable and
41
54
represents a key to classify C < @list > 's item under:
@@ -53,7 +66,7 @@ which the C<@list>'s item will be L«C<push>ed|/routine/push». See
53
66
L « C < .categorize-list > |/routine/categorize-list» if you wish to classify an item
54
67
into multiple categories at once.
55
68
56
- = head3 Multi-Level Classification
69
+ = head3 Multi-level classification
57
70
58
71
In multi-level classification mode, each mapper's value is an
59
72
L « C < Iterable > |/type/Iterable» that represents a tree of hash keys to classify
@@ -116,7 +129,7 @@ value respectively. A L«C<Callable>|/type/Callable» mapper will be executed
116
129
once per each item in the C < @list > , with that item as the argument and its
117
130
return value will be used as the mapper's value.
118
131
119
- = head3 Simple Categorization
132
+ = head3 Simple categorization
120
133
121
134
The mapper's value is expected to be a possibly empty list of
122
135
non-L « C < Iterables > |/type/Iterable» that represent categories to place the value
@@ -140,7 +153,7 @@ into:
140
153
141
154
Notice how some items, e.g. C < 6 > and C < 7 > , are present in several categories.
142
155
143
- = head3 Multi-Level Categorization
156
+ = head3 Multi-level categorization
144
157
145
158
In multi-level categorization, the categories produced by the mapper can are
146
159
L < Iterables|/type/Iterable > and categorization combines features
@@ -212,11 +225,11 @@ of the old value.
212
225
Example:
213
226
214
227
my %h = a => 1;
215
- %h.push: (a => 1); # a => [1,1]
216
- %h.push: (a => 1) xx 3 ; # a => [1,1,1,1,1]
217
- %h.push: (b => 3); # a => [1,1,1,1,1], b => 3
218
- %h.push('c' => 4); # a => [1,1,1,1,1], b => 3, c => 4
219
- push %h, 'd' => 5; # a => [1,1,1,1,1], b => 3, c => 4, d => 5
228
+ %h.push: (a => 1); # a => [1,1]
229
+ %h.push: (a => 1) xx 3 ; # a => [1,1,1,1,1]
230
+ %h.push: (b => 3); # a => [1,1,1,1,1], b => 3
231
+ %h.push('c' => 4); # a => [1,1,1,1,1], b => 3, c => 4
232
+ push %h, 'd' => 5; # a => [1,1,1,1,1], b => 3, c => 4, d => 5
220
233
221
234
Please note that C < Pair > s or
222
235
L < colon pairs|/language/glossary#index-entry-Colon_Pair > as arguments to push
@@ -234,7 +247,7 @@ index:
234
247
235
248
my %wc = 'hash' => 323, 'pair' => 322, 'pipe' => 323;
236
249
(my %inv).push: %wc.invert;
237
- say %inv; # OUTPUT: «{322 => pair, 323 => [pipe hash]}»
250
+ say %inv; # OUTPUT: «{322 => pair, 323 => [pipe hash]}»
238
251
239
252
Note that such a initialization could also be written as
240
253
@@ -364,8 +377,8 @@ Note that in the L<Scalar> case you have to use the C<VAR> method in
364
377
order to get correct information.
365
378
366
379
my $s is dynamic = %('apples' => 5);
367
- say $s.dynamic; # OUTPUT: «False» (wrong, don't do this)
368
- say $s.VAR.dynamic; # OUTPUT: «True» (correct approach)
380
+ say $s.dynamic; # OUTPUT: «False» (wrong, don't do this)
381
+ say $s.VAR.dynamic; # OUTPUT: «True» (correct approach)
369
382
370
383
= head1 Subscript Adverbs
371
384
@@ -375,7 +388,8 @@ for more information).
375
388
376
389
= head2 C < :exists >
377
390
378
- The adverb C < :exists > returns C < Bool::True > if a key exists in the Hash. If more than one key is supplied it returns a C < List > of C < Bool > .
391
+ The adverb C < :exists > returns C < Bool::True > if a key exists in the Hash. If more
392
+ than one key is supplied it returns a C < List > of C < Bool > .
379
393
380
394
my %h = a => 1, b => 2;
381
395
say %h<a>:exists; # OUTPUT: «True»
@@ -395,7 +409,8 @@ Use C<:delete> to remove a C<Pair> from the C<Hash>.
395
409
396
410
= head2 C < :p >
397
411
398
- The adverb C < :p > returns a C < Pair > or a List of C < Pair > instead of just the value.
412
+ The adverb C < :p > returns a C < Pair > or a List of C < Pair > instead of just the
413
+ value.
399
414
400
415
my %h = a => 1, b => 2;
401
416
say %h<a>:p; # OUTPUT: «a => 1»
0 commit comments