Skip to content

Commit 90ea0cd

Browse files
committed
Document List.first :k,:kv,:p,:end
And remove documentation for first-index / last-index
1 parent 80f4023 commit 90ea0cd

File tree

1 file changed

+28
-31
lines changed

1 file changed

+28
-31
lines changed

doc/Type/List.pod

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,9 @@ Defined as:
247247
Usage:
248248
249249
grep MATCHER, LIST
250+
grep MATCHER, LIST, :RETURN_AS
250251
LIST.grep(MATCHER)
252+
LIST.grep(MATCHER, :RETURN_AS)
251253
252254
Returns a sequence of elements against which C<$matcher> smart-matches.
253255
The elements are returned in the order in which they appear in the original
@@ -297,56 +299,51 @@ Examples:
297299
298300
Defined as:
299301
300-
multi sub first(Mu $matcher, *@elems)
301-
multi method first(List:D: Mu $matcher)
302+
multi sub first(Mu $matcher, *@elems, :k, :kv, :p, :end)
303+
multi method first(List:D: Mu $matcher, :k, :kv, :p, :end)
302304
303305
Usage:
304306
305-
first MATCHER, LIST
306-
LIST.first(MATCHER)
307+
first MATCHER, LIST, :RETURN_AS, :FROM_END
308+
LIST.first(MATCHER, :RETURN_AS, :FROM_END)
307309
308310
Returns the first item of the list which smart-matches against C<$matcher>,
309-
fails when no values match.
311+
returns Nil when no values match. The optional named parameter C<:end>
312+
indicates that the search should be from the B<end> of the list, rather than
313+
from the start.
310314
311315
Examples:
312316
313-
say (1, 22/7, 42).first: * > 5; # 42
314-
say $f = ('hello', 1, 22/7, 42, 'world').first: Complex;
315-
say $f.perl; # Failure.new(exception => X::AdHoc.new(payload => "No values matched"))
317+
say (1, 22/7, 42, 300).first: * > 5; # 42
318+
say (1, 22/7, 42, 300).first: * > 5, :end; # 300
319+
say ('hello', 1, 22/7, 42, 'world').first: Complex; # (Nil)
316320
317-
=head2 routine first-index
318-
319-
Defined as:
320-
321-
multi method first-index(List:D: Mu $matcher)
322-
323-
Usage:
324-
325-
LIST.first-index(MATCHER)
326-
327-
Returns the first index against which C<$matcher> smart-matches, or C<Nil> if
328-
no match was found.
321+
The optional named parameters C<:k>, C<:kv>, C<:p> provide the same
322+
functionality as on slices:
329323
330-
Example:
324+
=over 4
331325
332-
say (1, 22/7, 42, 300, 72).first-index: * > 5; # 2
326+
=item k
333327
334-
=head2 routine last-index
328+
Return the index value of the matching element. Index is always counted from
329+
the beginning of the list, regardless of whether the C<:end> named parameter
330+
is specified or not.
335331
336-
Defined as:
332+
=item kv
337333
338-
multi method last-index(List:D: Mu $matcher)
334+
Return both the index and matched element.
339335
340-
Usage:
336+
=item p
341337
342-
LIST.last-index(MATCHER)
338+
Return the index and the matched element as a C<Pair>.
343339
344-
Returns the last index against which C<$matcher> smart-matches, or C<Nil> if
345-
no match was found.
340+
=back
346341
347-
Example:
342+
Examples:
348343
349-
say (1, 22/7, 42, 300, 72).last-index: * > 5; # 4
344+
say (1, 22/7, 42, 300).first: * > 5, :k; # 2
345+
say (1, 22/7, 42, 300).first: * > 5, :p; # 2 => 42
346+
say (1, 22/7, 42, 300).first: * > 5, :kv, :end; # 3 300
350347
351348
=head2 routine classify
352349

0 commit comments

Comments
 (0)