Documentation for routine comb

Documentation for routine comb, assembled from the following types:

class Cool

From Cool

(Cool) routine comb

Defined as:

multi sub comb(Regex $matcherStr(Cool$input$limit = * --> Seq)
multi method comb(Regex $matcher$limit = * --> Seq)

Returns all (or if supplied, at most $limit) matches of the invocant (method form) or the second argument (sub form) against the Regex as a list of strings.

say "6 or 12".comb(/\d+/).join("");           # OUTPUT: «6, 12␤» 

class Str

From Str

(Str) routine comb

multi sub    comb(Str:D   $matcherStr:D $input$limit = Inf)
multi sub    comb(Regex:D $matcherStr:D $input$limit = InfBool :$match)
multi sub    comb(Int:D $sizeStr:D $input$limit = Inf)
multi method comb(Str:D $input:)
multi method comb(Str:D $input: Str:D   $matcher$limit = Inf)
multi method comb(Str:D $input: Regex:D $matcher$limit = InfBool :$match)
multi method comb(Str:D $input: Int:D $size$limit = Inf)

Searches for $matcher in $input and returns a list of all matches (as Str by default, or as Match if $match is True), limited to at most $limit matches.

If no matcher is supplied, a list of characters in the string (e.g. $matcher = rx/./) is returned.


say "abc".comb.perl;                 # OUTPUT: «("a", "b", "c").Seq␤» 
say 'abcdefghijk'.comb(3).perl;      # OUTPUT: «("abc", "def", "ghi", "jk").Seq␤» 
say 'abcdefghijk'.comb(32).perl;   # OUTPUT: «("abc", "def").Seq␤» 
say comb(/\w/"a;b;c").perl;        # OUTPUT: «("a", "b", "c").Seq␤» 
say comb(/\N/"a;b;c").perl;        # OUTPUT: «("a", ";", "b", ";", "c").Seq␤» 
say comb(/\w/"a;b;c"2).perl;     # OUTPUT: «("a", "b").Seq␤» 
say comb(/\w\;\w/"a;b;c"2).perl# OUTPUT: «("a;b",).Seq␤» 

If the matcher is an integer value, it is considered to be a matcher that is similar to / . ** matcher /, but which is about 30x faster.

class IO::Handle

From IO::Handle

(IO::Handle) method comb

multi method comb(IO::Handle:D: :$close = False)
multi method comb(IO::Handle:D: Int:D $size:$close = False)
multi method comb(IO::Handle:D: $comber:$close = False)

Returns a lazy list of strings combed from the handle, just like comb on strings.

my $fh = open 'path/to/file':r;
$fn.comb(/A+/); # Comb file contents by a regex. 


my $fh = open 'path/to/file':r;
$fn.comb(3close => True); # Comb file contents by 3 characters and close after.