Skip to content

Commit 49782b4

Browse files
committed
List.first, .classify
1 parent 4d7d3f0 commit 49782b4

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

lib/List.pod

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,34 @@ the return values are accessed.
3232
=head2 grep
3333
3434
multi sub grep(Mu $matcher, *@elems) returns List:D
35-
multi method grep(List:D:, Mu $matcher) returns List:D
35+
multi method grep(List:D: Mu $matcher) returns List:D
3636
3737
Returns a lazy list of elements against which C<$matcher> smart-matches.
3838
The elements are returned in the order in which they appear in the original
3939
list.
4040
41+
=head2 first
42+
43+
multi sub first(Mu $matcher, *@elems)
44+
multi method first(List:D: Mu $matcher)
45+
46+
Returns the first item of the list which smart-matches against C<$matcher>.
47+
48+
=head2 classify
49+
50+
multi sub classify(&mapper, *@values) returns Hash:D
51+
multi method classify(List:D: &mapper) returns Hash:D
52+
53+
C<classify> transforms a list or array of values into a hash
54+
representing the classification of those values according to a mapper;
55+
each hash key represents the classification for one or more of the
56+
incoming list values, and the corresponding hash value contains
57+
an array of those list values classified by the mapper into the category
58+
of the associated key. For example:
59+
60+
my @list = (1, 2, 3, 4);
61+
my %h = classify { $_ % 2 ?? 'odd' !! 'even' }, @list;
62+
63+
Creates the hash C<< { odd => [1, 3], even => [2, 4] } >> in C<%h>.
64+
4165
=end pod

0 commit comments

Comments
 (0)