On 12/10/2002 4:54 AM, Me wrote:
I belive the short answer is "make sure all elements of your pipeline return a lazy list". Exactly how one does this, and the distinction between a lazy list and an iterator, I belive is still somwhat up in the air. (If I'm wrong, please correct me.)How would one most nicely code what I'll call a lazy pipeline, such that the first result from the final element of the pipeline can appear as soon as the first result has been processed from the intervening elements?
IOW:
foreach (map {$_+1} grep {$_>0} @foo but lazy) {
do_somthing_here($_);
die "Bye-bye universe!" if ($_=42);
}
Will never compute anything after the first 41 element in @foo occours. (I'm assuming map, grep, and any other list-oriented function that can get away with it will act lazily when given a lazy-list argument.)
-=- James Mastros