On Thu, 21 Mar 2019 at 16:15, Rowan Collins <rowan.coll...@gmail.com> wrote:
>
> On Thu, 21 Mar 2019 at 15:21, Robert Hickman <robehick...@gmail.com> wrote:
>>
>> In this case nextIf() would have to be implemented something like:
>>
>> function nextif($someCondition) {
>>     foreach($this->iteratorValue as $x) {
>>         if(<some comparison of $x and $$someCondition) {
>>              yield $x;
>>         }
>>     }
>> }
>>
>> iterator_to_array would need an internal loop to pull the values from
>> the generator.
>
>
>
> I think it would be more like this:
>
> function nextif($someCondition) {
>     do {
>         $this->currentIndex++;
>         $x = $this->items[ $this->currentIndex ];
>     } while ( ! some comparison of $x and $$someCondition);
>     return $x;
> }
>

Thanks, that makes sense.

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to