>> 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.
>  I don't think I ever used
> the generator one in python (I use list one all the time), and I maybe
> used analogous construct in PHP once or twice (and again I use array_map
> and more complex syntax for array transformations all the time).
>
I use generator expressions rarely in python, usually as a conditional
'if any data in x match condition':

if not next((True for flter in config['pull_ignore_filters'] if
fnmatch.fnmatch(fle['path'], flter)), False):
filtered_pull_files.append(fle)

I use the list form for filtering, and the dict form mostly for
creating an index of a sub-value as noted before. I don't use
generators at all in PHP right now, but do make extensive use of loops
doing filters and building indexes. An 'array comprehension' syntax
would be welcome from me.

One needs to be contentions that people use tools differently, so 'I
don't use something' isn't the same as 'nobody uses something'.

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

Reply via email to