user
A generator is an executable entity (like a function or procedure) that contains code that yields a sequence of values, one at a time, so that each time you call the generator, the next value in the sequence is provided.

Generators are often built on top of coroutines or objects so that the internal state of the object is handled “naturally”.

Generators are often used in situations where a sequence is potentially infinite, and where it is possible to construct the next value of the sequence with only minimal state.

Task

* Create a function that returns a generation of the m'th powers of the positive integers starting from zero, in order, and without obvious or simple upper limit. (Any upper limit to the generator should not be stated in the source but should be down to factors such as the languages natural integer size limit or computational time/size).
* Use it to create a generator of:

:   :   :   * Squares.
            * Cubes.

* Create a new generator that filters all cubes from the generator of squares.
* Drop the first 20 values from this last generator of filtered results, and then show the next 10 values.

Note that this task *requires* the use of generators in the calculation of the result.

Also see

* Generator
assistant
(formerly Perl 6)

As with Haskell, generators are disguised as lazy lists in Raku.

```
sub powers($m) { 0..* X** $m }

my @squares = powers(2);
my @cubes   = powers(3);

sub infix:<with-out> (@orig, @veto) {
    gather for @veto -> $veto {
        take @orig.shift while @orig[0] before $veto;
        @orig.shift if @orig[0] eqv $veto;
    }
}

say (@squares with-out @cubes)[20 ..^ 20+10].join(', ');

```

Output:

```
529, 576, 625, 676, 784, 841, 900, 961, 1024, 1089
```