Skip to content

Commit 80f4023

Browse files
committed
Document grep :k,:kv,:p,:v, remove grep-index
1 parent 1bcaafd commit 80f4023

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

doc/Type/List.pod

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,8 @@ invokes C<uc|/type/Str#routine uc> four times.
241241
242242
Defined as:
243243
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
246246
247247
Usage:
248248
@@ -260,25 +260,38 @@ Examples:
260260
> grep { .Str.chars > 3 }, 'hello', 1, 22/7, 42, 'world'
261261
(hello 3.142857 world)
262262
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:
264265
265-
Defined as:
266+
=over 4
266267
267-
multi method grep-index(List:D: Mu $matcher) returns Seq:D
268+
=item k
268269
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
270281
271-
LIST.grep-index(MATCHER)
282+
Only return the matched elements (same as not specifying any named parameter
283+
at all).
272284
273-
Returns a sequence of indices against which the associated elements
274-
smart-match. The indices are returned in order.
285+
=back
275286
276287
Examples:
277288
278-
> ('hello', 1, 22/7, 42, 'world').grep-index: Int
289+
> ('hello', 1, 22/7, 42, 'world').grep: Int, :k
279290
(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)
282295
283296
=head2 routine first
284297

0 commit comments

Comments
 (0)