Documentation for routine words

Documentation for routine words, assembled from the following types:

class Cool

From Cool

(Cool) method words

Defined as:

method words(Int() $limit)

Coerces the invocant to Str, and returns a list of words that make up the string (and if $limit is supplied, only the first $limit words).

say 'The quick brown fox'.words.join('|');      # OUTPUT: «The|quick|brown|fox␤» 
say 'The quick brown fox'.words(2).join('|');   # OUTPUT: «The|quick␤» 

Only whitespace counts as word boundaries

say "isn't, can't".words.join('|');             # OUTPUT: «isn't,|can't␤» 

class Str

From Str

(Str) routine words

multi sub    words(Str:D $input$limit = Inf --> Positional)
multi method words(Str:D $input: $limit = Inf --> Positional)

Returns a list of non-whitespace bits, i.e. the same as a call to $input.comb( / \S+ /, $limit ) would.

Examples:

say "a\nb\n".words.perl;       # OUTPUT: «("a", "b").Seq␤» 
say "hello world".words.perl;  # OUTPUT: «("hello", "world").Seq␤» 
say "foo:bar".words.perl;      # OUTPUT: «("foo:bar",).Seq␤» 
say "foo:bar\tbaz".words.perl# OUTPUT: «("foo:bar", "baz").Seq␤» 

class IO::Handle

From IO::Handle

(IO::Handle) method words

method words($count = Inf)

Return a lazy list of the file's words (separated on whitespace), limited to $count words.

my %dict;
++%dict{$_} for $*IN.words;
say "Most common words: "%dict.sort(*.value).reverse.[^5];

class Supply

From Supply

(Supply) method words

method words(Supply:D: --> Supply:D)

Creates a supply that will emit the characters coming in word for word from a supply that's usually created by some asynchronous I/O operation.