Re: RFC Draft: Comprehensions
| From: | Robert Hickman | Date: | Wed, 20 Mar 2019 00:28:31 +0000 |
| Subject: | Re: RFC Draft: Comprehensions | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-104814@lists.php.net to get a copy of this message | ||
> > In python comprehensions on [] makes a list and comprehensions in {}
> > make a dictionary (list and dict comprehensions). As PHP only has one
> > 'array' type using [] makes sense. Along that train of thought, should
> > comprehensions also be possible in the old array() syntax?
>
> Honestly, I cannot think of any case where I'd use a comprehension where I would
> definitely want an array and not a generator. In the majority case both work equally well, cool,
> but I don't know when I would even use an array-dependent version. And converting from a
> generator to an array is trivial; the other way, very not so much.
>
Would there be any notable performance difference? I'd expect the case
where one actually wanted the whole array to be slower if it was going
through a generator, vs a tight loop, due to the additional level of
indirection.