Documentation for routine grep

Documentation for routine grep, assembled from the following types:

class Any

From Any

(Any) method grep

Defined As:

    method grep(--> TODO)

TODO

class List

From List

(List) routine grep

Defined as:

sub    grep(Mu $matcher*@elems:$k:$kv:$p:$v --> Seq:D)
method grep(List:D:  Mu $matcher:$k:$kv:$p:$v --> Seq:D)

Returns a sequence of elements against which $matcher smart-matches. The elements are returned in the order in which they appear in the original list.

Examples:

say ('hello'122/742'world').grep: Int;              # OUTPUT: «(1 42)␤» 
say grep { .Str.chars > 3 }'hello'122/742'world'# OUTPUT: «(hello 3.142857 world)␤» 

The optional named parameters :k, :kv, :p, :v provide the same functionality as on slices:

Only return the index values of the matching elements in order.

Return both the index and matched elements in order.

Return the index and the matched element as a Pair, in order.

Only return the matched elements (same as not specifying any named parameter at all).

Examples:

say ('hello'122/742'world').grep: Int:k;
# OUTPUT: «(1 3)␤» 
say grep { .Str.chars > 3 }:kv'hello'122/742'world';
# OUTPUT: «(0 hello 2 3.142857 4 world)␤» 
say grep { .Str.chars > 3 }:p'hello'122/742'world';
# OUTPUT: «(0 => hello 2 => 3.142857 4 => world)␤» 

class Supply

From Supply

(Supply) method grep

method grep(Supply:D: Mu $test --> Supply:D)

Creates a new supply that only emits those values from the original supply that smart-match against $test.

my $supplier = Supplier.new;
my $all      = $supplier.Supply;
my $ints     = $all.grep(Int);
$ints.tap(&say);
$supplier.emit($_for 1'a string'3.14159;   # prints only 1