Skip to content

Instantly share code, notes, and snippets.

@hakobe
Created February 2, 2009 06:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hakobe/56808 to your computer and use it in GitHub Desktop.
Save hakobe/56808 to your computer and use it in GitHub Desktop.
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