@@ -241,8 +241,8 @@ invokes C<uc|/type/Str#routine uc> four times.
241
241
242
242
Defined as:
243
243
244
- multi sub grep(Mu $matcher, *@elems) returns Seq:D
245
- multi method grep(List:D: Mu $matcher) returns Seq:D
244
+ multi sub grep(Mu $matcher, *@elems, :k, :kv, :p, :v ) returns Seq:D
245
+ multi method grep(List:D: Mu $matcher, :k, :kv, :p, :v ) returns Seq:D
246
246
247
247
Usage:
248
248
@@ -260,25 +260,38 @@ Examples:
260
260
> grep { .Str.chars > 3 }, 'hello', 1, 22/7, 42, 'world'
261
261
(hello 3.142857 world)
262
262
263
- = head2 routine grep-index
263
+ The optional named parameters C < :k > , C < :kv > , C < :p > , C < :v > provide the same
264
+ functionality as on slices:
264
265
265
- Defined as:
266
+ = over 4
266
267
267
- multi method grep-index(List:D: Mu $matcher) returns Seq:D
268
+ = item k
268
269
269
- Usage:
270
+ Only return the index values of the matching elements in order.
271
+
272
+ = item kv
273
+
274
+ Return both the index and matched elements in order.
275
+
276
+ = item p
277
+
278
+ Return the index and the matched element as a C < Pair > , in order.
279
+
280
+ = item v
270
281
271
- LIST.grep-index(MATCHER)
282
+ Only return the matched elements (same as not specifying any named parameter
283
+ at all).
272
284
273
- Returns a sequence of indices against which the associated elements
274
- smart-match. The indices are returned in order.
285
+ =back
275
286
276
287
Examples:
277
288
278
- > ('hello', 1, 22/7, 42, 'world').grep-index : Int
289
+ > ('hello', 1, 22/7, 42, 'world').grep: Int, :k
279
290
(1 3)
280
- > grep-index { .Str.chars > 3 }, 'hello', 1, 22/7, 42, 'world'
281
- (0 2 4)
291
+ > grep { .Str.chars > 3 }, :kv, 'hello', 1, 22/7, 42, 'world'
292
+ (0 hello 2 3.142857 4 world)
293
+ > grep { .Str.chars > 3 }, :p, 'hello', 1, 22/7, 42, 'world'
294
+ (0 => hello 2 => 3.142857 4 => world)
282
295
283
296
= head2 routine first
284
297
0 commit comments