Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
use strict;
use warnings;
use Coro::Generator;
use Perl6::Say;
sub count {
my $start = shift;
generator {
my $n = $start;
while (1) {
yield $n++;
}
}
}
sub fib {
generator {
my $n = 0;
my $m = 1;
yield $n;
yield $m;
while (1) {
yield $n+$m;
($n, $m) = ($m, $n+$m);
}
}
}
my $c = count();
for (0..9) {
say $c->();
}
say;
my $f = fib();
for (0..9) {
say $f->();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment