On Tuesday, December 10, 2002, 1:26:41 PM, you (mailto:[EMAIL PROTECTED]) wrote:
> On 12/10/2002 4:54 AM, Me wrote:
>> 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?
> 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.

I think the answer here will be make a lazy list an iterator constructor. This
would also be the case for something like a grep in the pipeline (in effect an
iterator adaptor -- to use a C++ term -- on the previous iterator).

I.e. in a "lazy context", grep would return an object with implementation
something like:

sub GrepIterator.atEnd {
   return $inputIt.atEnd;
}

sub GrepIterator.Next(): boolean {
   while ($inputIt.Next() and $inputIt.Value() !~ $myPattern) {}
   if .atEnd() {
      return 0;
   }

   $myCurrent = $inputIt.Value();
   return 1;
}

sub GrepIterator.Value() {
    return $myCurrent();
}

(Which of course misses all the edge cases.)

-- 
Richard
mailto:[EMAIL PROTECTED]

Reply via email to