Raku By Example
View me onGitHub
## take in the function

sub weird(@elems, :$direction = 'forward') {
    my %direction = (
        forward  => sub { take $_ for @elems },
        backward => sub { take $_ for @elems.reverse },
        random   => sub { take $_ for @elems.pick(*) },
    );
    return gather %direction{$direction}();
}

say weird(<a b c>, :direction<backward> );          # (c b a)

## lazy gather take

my @vals = lazy gather {
    for ^Inf {
        take $_ if .is-prime;
    }
}

say @vals[10000];
say now - INIT now;

## gather for take

my $n = 20;
my @a = gather for 1..$n -> $x {
         for $x..$n -> $y {
           for $y..$n -> $z {
             take $x,$y,$z if $x² + $y² == $z²;
           }
         }
       };
.say for @a;

## gather for take 

my @a = 1..20;
my @c = gather for @a.combinations(3.permutations {
     #{ for .Array {.say if .[0]*.[0] + .[1]*.[1] == .[2] * .[2] } }
    take .[0], .[1], .[2] if .[0+ .[1== .[2for .Array;
}

say @c;