#!/usr/bin/perl
#
# eg13: 3rd iterator example - upto(min,max) function factory
#

use strict;
use warnings;
use Function::Parameters qw(:strict);

#
# my $it = upto( $min, $max ):
#	Make an iterator that counts from $min upwards
#	to $max and then fails..
#
fun upto( $n, $max )
{
	return fun {
		return undef if $n > $max;
		return $n++;
	};
}

my $counter = upto( 1, 10 );
while( my $n = $counter->() )
{
	print "counter: $n\n";
}
