@@ -247,7 +247,9 @@ Defined as:
247
247
Usage:
248
248
249
249
grep MATCHER, LIST
250
+ grep MATCHER, LIST, :RETURN_AS
250
251
LIST.grep(MATCHER)
252
+ LIST.grep(MATCHER, :RETURN_AS)
251
253
252
254
Returns a sequence of elements against which C < $matcher > smart-matches.
253
255
The elements are returned in the order in which they appear in the original
@@ -297,56 +299,51 @@ Examples:
297
299
298
300
Defined as:
299
301
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 )
302
304
303
305
Usage:
304
306
305
- first MATCHER, LIST
306
- LIST.first(MATCHER)
307
+ first MATCHER, LIST, :RETURN_AS, :FROM_END
308
+ LIST.first(MATCHER, :RETURN_AS, :FROM_END )
307
309
308
310
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.
310
314
311
315
Examples:
312
316
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 )
316
320
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:
329
323
330
- Example:
324
+ = over 4
331
325
332
- say (1, 22/7, 42, 300, 72).first-index: * > 5; # 2
326
+ = item k
333
327
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.
335
331
336
- Defined as:
332
+ = item kv
337
333
338
- multi method last- index(List:D: Mu $matcher)
334
+ Return both the index and matched element.
339
335
340
- Usage:
336
+ = item p
341
337
342
- LIST.last-index(MATCHER)
338
+ Return the index and the matched element as a C < Pair > .
343
339
344
- Returns the last index against which C < $matcher > smart-matches, or C < Nil > if
345
- no match was found.
340
+ =back
346
341
347
- Example :
342
+ Examples :
348
343
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
350
347
351
348
= head2 routine classify
352
349
0 commit comments