#!/usr/bin/perl
#
# eg14: 4th iterator example - two upto(min,max) counters
#

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 $c1 = upto( 1, 10 );
my $c2 = upto( 100, 103 );

while(1)
{
	my $n1 = $c1->();
	my $n2 = $c2->();
	last unless defined $n1 && defined $n2;
	print "c1: $n1, c2: $n2\n";
}
