Perl6 Wiki


77pages on
this wiki

Gather is syntactic sugar for creating an Array, that is by gathering up a bunch of things to take into the Array.

Description Edit

Gather is a statement that encloses take statements. The take control structure can never be used outside of the gather structure in Perl6. Gather returns an Array such that whenever take is ran it pushes to the array that gather instantiated in the beggining.

General Structure Edit

gather { take $value; } 

Alternative Notation Edit

(sub {
	my @arr;


	return @arr;

Examples Edit

Get lower case words Edit

sub getLowerCaseWords(Str $phrase) {

	gather {
		take $_ if $_ eq .lc for $phrase.words;


getLowerCaseWords("This phrase is a test").join(", ").say;

Around Wikia's network

Random Wiki