Re: RFC Draft: Comprehensions
| From: | Robert Hickman | Date: | Thu, 21 Mar 2019 18:40:23 +0000 |
| Subject: | Re: RFC Draft: Comprehensions | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-104861@lists.php.net to get a copy of this message | ||
On Thu, 21 Mar 2019 at 16:15, Rowan Collins <rowan.collins@gmail.com> wrote:
>
> On Thu, 21 Mar 2019 at 15:21, Robert Hickman <robehickman@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.