Skip to content

Commit 01c9f44

Browse files
committed
Added some identical method based examples, seemed appropriate
1 parent dca94f7 commit 01c9f44

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

S32-setting-library/Containers.pod

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,16 @@ an array of those list values classified by the mapper into the category
170170
of the associated key. For example:
171171

172172
@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
174175

175176
In this example, @even will contain all even numbers from C<@list>
176177
and C<@odd> will contain all odd numbers from C<@list>.
177178

178179
To simply transform a list into a hash of arrays:
179180

180-
%cars_by_color := classify { .color }, @cars;
181+
%cars_by_color := @cars.classify: { .color };
182+
%cars_by_color := classify { .color }, @cars; # same
181183
red_car_owners(%cars_by_color<red>.map:{.owner});
182184

183185
A mapper may be any unary function, hash, or array.
@@ -223,7 +225,8 @@ the C<$test> smart-matches as true.
223225

224226
Here is an example of its use:
225227

226-
@friends = grep { .is_friend }, @coworkers;
228+
@friends = @coworkers.grep: { .is_friend };
229+
@friends = grep { .is_friend }, @coworkers; # same
227230

228231
This takes the array C<@coworkers>, checks every element to see
229232
which ones return true for the C<.is_friend> method, and returns

0 commit comments

Comments
 (0)