The "assignment from a lazy list" section of RFC 123 suggests a system
for requesting the first however many items out of a map or grep by
making it lazy and then assigning it to an array of that size.  

"last" is more flexible, if you are looking for a condition more
complex than the first one, say you want all the temperature on all
the days preceding the day the all-time record was broken, you can do
that with "last" if you have the old record, otherwise you need to
iterate over and refuse the rest of the records.

Using a function-based lazy list


        @days_up_to_recordbreaker = () = lazy {
                my $day;
                while($day++){
                    (yield $high[$day]) > $AllTimeRecord and return ();
                }
        }


Using grep without last

  
        my $unbroken = 1;
        @days_up_to_recordbreaker = @high [
                grep {
                        $unbroken &&= $high[$_] <= $AllTimeRecord
                } (0..$#high)
        ]

        
Using for/push

        for @high {
                push @days_up_to_recordbreaker, $_;
                last if $high[$_] > $AllTimeRecord;     
        }



Using map/last

        @days_up_to_recordbreaker = map{
                $_ > $AllTimeRecord

                ?
                        $_ , last       # is this right?

                :
                        $_
                
        } @high


I wrote a map w/o last but erased it for brevity :)

-- 
                          David Nicol 816.235.1187 [EMAIL PROTECTED]
          perl -e'map{sleep print$w[rand@w]}@w=<>' /usr/dict/words

Reply via email to