@@ -170,14 +170,16 @@ an array of those list values classified by the mapper into the category
170
170
of the associated key. For example:
171
171
172
172
@list = (1, 2, 3, 4);
173
- (:@even, :@odd) := classify { $_ % 2 ?? 'odd' !! 'even' }, @list;
173
+ (:@even, :@odd) := @list.classify: { $_ % 2 ?? 'odd' !! 'even' };
174
+ (:@even, :@odd) := classify { $_ % 2 ?? 'odd' !! 'even' }, @list; # same
174
175
175
176
In this example, @even will contain all even numbers from C<@list>
176
177
and C<@odd> will contain all odd numbers from C<@list>.
177
178
178
179
To simply transform a list into a hash of arrays:
179
180
180
- %cars_by_color := classify { .color }, @cars;
181
+ %cars_by_color := @cars.classify: { .color };
182
+ %cars_by_color := classify { .color }, @cars; # same
181
183
red_car_owners(%cars_by_color<red>.map:{.owner});
182
184
183
185
A mapper may be any unary function, hash, or array.
@@ -223,7 +225,8 @@ the C<$test> smart-matches as true.
223
225
224
226
Here is an example of its use:
225
227
226
- @friends = grep { .is_friend }, @coworkers;
228
+ @friends = @coworkers.grep: { .is_friend };
229
+ @friends = grep { .is_friend }, @coworkers; # same
227
230
228
231
This takes the array C<@coworkers>, checks every element to see
229
232
which ones return true for the C<.is_friend> method, and returns
0 commit comments