#!/usr/bin/perl
#
# eg21: 4th lazylist example, use merge_l..
#

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

use List;
$List::as_string_limit = 8;

# $list = stepup( $n, $step ) - return an infinite list n, n+step, n+2*step...
fun stepup( $n, $step )
{
	return List->cons( $n, fun { stepup($n+$step,$step); } );
}

my $odds  = stepup( 1, 2 );
print "first few odd values: $odds\n";

my $evens = stepup( 2, 2 );
print "first few even values: $evens\n";

my $all   = merge_l { $a <=> $b } $odds, $evens;
print "first few merged values: $all\n";
