Created
September 13, 2010 02:55
-
-
Save mfollett/576739 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| my $stream; | |
| { | |
| my $previous = 0; | |
| $stream = sub { $previous++ }; | |
| } | |
| my $limited_stream; | |
| { | |
| my $previous = 0; | |
| $limited_stream = sub { return $previous if $previous++ < 10; return; }; | |
| } | |
| my $limited_even_stream; | |
| { | |
| my $previous = 0; | |
| $limited_even_stream = sub { return $previous if(($previous+=2) <= 10); return; }; | |
| } | |
| sub say_numbers_in_stream | |
| { | |
| my $stream = shift; | |
| while( defined (my $val = $stream->() ) ) | |
| { | |
| say "We've reached number $val!"; | |
| } | |
| } | |
| say_numbers_in_stream($limited_stream); | |
| say_numbers_in_stream($limited_even_stream); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment